#How do I make a ball follow me and kick me if it touches me?

14 messages · Page 1 of 1 (latest)

fierce rock
#

Rookie here, what kind of script do I need for that? I keep trying and nothing is working or helping me, not even YouTube vids 🙏

last finch
atomic pawn
atomic pawn
#

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

last finch
fierce rock
last finch
#
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)```