Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My Follow Script isnt working on real Roblox but on Studio, But it has no errors ?

Asked by 6 years ago

I don't know why. My Follow script wont work on Roblox, It does in studio but not in real Roblox can you help? The Zombie I made should follow the closest player, but it in studio is works but on Roblox they just stand still

local humanoid = script.Parent.Zombie
local Torso = script.Parent.Torso
local MaxDistance = 999999999999

function MoveTowardsAPerson(pos)
    local People = {}
    local MoveTo
    for i,v in pairs(workspace:GetChildren()) do
        if v:IsA("Model") and v:findFirstChild("Humanoid") then
            if game.Players:GetPlayerFromCharacter(v) then
                table.insert(People,v)
            end
        end
    end

    for i,v in pairs(People) do
        local pos2 = v.Torso.Position
        local mag = (pos - pos2).magnitude

        if mag <= MaxDistance and game.Players:FindFirstChild(v.Name).CanFollow.Value == true then
            MoveTo = v.Torso
        end
    end

    if MoveTo ~= nil then
        return MoveTo
    end
end

while game:GetService("RunService").RenderStepped:wait() do
    if humanoid.Health > 1 then
        local t = MoveTowardsAPerson(Torso.Position)
        if t ~= nil then
            humanoid:MoveTo(t.Position)
        end
    end
end

0
Perhaps try adding a wait at the beginning? ohhel 2 — 6y

1 answer

Log in to vote
0
Answered by
lukeb50 631 Moderation Voter
6 years ago

You are using RenderStepped in a script.

Because the client-server relation is different in studio, renderstepped will fire in a script, but on a real server it will only fire in LocalScripts.

More info:http://wiki.roblox.com/index.php?title=API:Class/RunService/RenderStepped

Ad

Answer this question