Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What's Wrong With This Script, The End Statements?

Hello, Sometimes, When I'm Only One Testing It, It Works Perfect. But When I Do Test With Other "Players" It Doesn't Work, Sometimes Script Does The Simon Part first but it doesn't choose Simon or teleport, Have I Done the End Statements Wrong?

local s = script.Stat
----------------- CountDown---------

t= 0
while true do
	t= 10
	repeat
		t= t-1
		s.Value = "Teleporting Players In "..t
		wait(1)
	until t == 0
	

---------------- Teleport Players -----------
function teleAll(x, y, z)
    local pos = Vector3.new(x, y, z)
    for i, plr in pairs(game:GetService("Players"):GetPlayers()) do
        if plr.Character and plr.Character.HumanoidRootPart then
            plr.Character:MoveTo(pos)
        end
    end
end

teleAll(201, -11.5, 181.5)

-------------------------------------------------------
wait(3)
t= 6
repeat
	t= t-1
	s.Value = "Choosing simon in "..t
	wait(1)
until t == 0


local simon = game.Players:GetPlayers()
[math.random(1, #game.Players:GetPlayers())]
print("Random player has been chosed")
simonpl = CFrame.new(200, 0.5, 229)
simon.Character:MoveTo(simonpl)
end

1 answer

The reason it works when you play solo but not when you play with other characters is because when you click the play button your character is loaded before the game and scripts are. But when you do test it loads the normal way with the server loading first then the players. You have to add code to make the script wait for the players character to load. You can make the game wait for a character using plr:WaitForCharacter() I cant test that this will work right now so let me know if it does. :)

local s = script.Stat
----------------- CountDown---------

t= 0
while true do
    t= 10
    repeat
        t= t-1
        s.Value = "Teleporting Players In "..t
        wait(1)
    until t == 0


---------------- Teleport Players -----------
function teleAll(x, y, z)
    local pos = Vector3.new(x, y, z)
    for i, plr in pairs(game:GetService("Players"):GetPlayers()) do
	plr:WaitForCharacter()
        if plr.Character and plr.Character.HumanoidRootPart then
            plr.Character:MoveTo(pos)
        end
    end
end

teleAll(201, -11.5, 181.5)

-------------------------------------------------------
wait(3)
t= 6
repeat
    t= t-1
    s.Value = "Choosing simon in "..t
    wait(1)
until t == 0


local simon = game.Players:GetPlayers()
[math.random(1, #game.Players:GetPlayers())]
print("Random player has been chosed")
simonpl = CFrame.new(200, 0.5, 229)
simon.Character:MoveTo(simonpl)
end

1 comment

0

It Doesn't Work Sir, Still it's the same problem :(

This discussion is preserved as it was. New answers, comments, and votes are closed.