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

How do I make this constantly update the playerbase?

Asked by 10 years ago

So, I got this script so that when someone says "Help" they tp to me.

mk = game.Players:GetChildren()
for i=1, #mk do
mk[i].Chatted:connect(function(Msg)
if Msg == "Help" then
mk[i].Character.Torso.CFrame = CFrame.new(Workspace.jaytheidiot.Torso.CFrame.X+5,Workspace.jaytheidiot.Torso.CFrame.Y+2,Workspace.jaytheidiot.Torso.CFrame.Z)
end
end)
end

How do I make it so the playerbase is constantly updated? With this only the people who were there when I ran it can use it.

1 answer

Log in to vote
1
Answered by
Yvori 25
10 years ago

An easy way to fix this is to put the whole thing in an infinite loop. That way, every 0.01 seconds or so it will check the list of players again.

while true do
    wait()
    local mk = game.Players:GetChildren()
    for i=1, #mk do
        mk[i].Chatted:connect(function(Msg)
            if Msg == "Help" then
                mk[i].Character.Torso.CFrame = CFrame.new(Workspace.jaytheidiot.Torso.CFrame.X+5,Workspace.jaytheidiot.Torso.CFrame.Y+2,Workspace.jaytheidiot.Torso.CFrame.Z)
            end
        end)
    end
end
Ad

Answer this question