#How do I make a ball follow me and kick me if it touches me?
14 messages · Page 1 of 1 (latest)
uh kick me in the sense ur refering to like Kicking from game or Kick( like throw you away)?
- make a function called findclosestplayer
- make the ball move to the closestplayer (you)
- use a touched event to see if the ball touches you (id reccomend using a hitbox)
- "kick" you
Kick me as from the game!
That sounds difficult 😭
well
its not that difficult
how are you gonna move the ball?
thats really the only difficult part I can think of, use an animation?
or w physics idrk how youd do that
Did you found the solution or shall I give you full code with explanation?
I didn't find the solution yettt, that would be great if you did 🙏
here..sry i forgot
local RunService = game:GetService("RunService")
local followingPart = workspace.FollowerPart
local SPEED = 15
local MAX_DISTANCE = 50
-- change those two to watever u want..
local function getNearestPlayer()
local nearestDist = MAX_DISTANCE
local nearest = nil
for _, player in ipairs(Players:GetPlayers()) do
local root = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
if root then
local dist = (root.Position - followingPart.Position).Magnitude
if dist < nearestDist then
nearestDist = dist
nearest = root
end
end
end
return nearest
end
RunService.Heartbeat:Connect(function(dt)
local target = getNearestPlayer()
if target then
local direction = (target.Position - followingPart.Position).Unit
followingPart.Position += direction * SPEED * dt
end
end)
followingPart.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
player:Kick("your message here")
end
end)```