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

Why isn't my for loop teleport script working? For loop teleport not working..

So I wrote a Server Script to teleport ALL players to a position when the intermission is up. I thought I could use a for loop to teleport them all but it doesn't seem to be working.

I'll explain with comments in the code block below..

local players = game.Players:GetChildren()
local roundRunning = false
local Intermission = true

if Intermission == true then
	local intermissionHint = Instance.new("Hint", workspace)
	for i = 30, 0, -1 do
		intermissionHint.Text = "Intermission: "..i
		wait(1)
		if i == 0 then
			wait(1)
			intermissionHint:Destroy()
			Intermission = false
			roundRunning = true
		end
	end
end

if roundRunning == true then
	for i,v in pairs(players) do  -- SO eh here. Yeah.
                                                    --[[ So as you can see here I tried to teleport all players in the server here. ]]--    
		v.Character.HumanoidRootPart.CFrame = CFrame.new(23.09, 11.473, 8.84)
	end
end

Anyone got any idea why this isn't working??

1 answer

✓ Accepted answer

Personally, I would use a pre-determined function in collaboration with your Intermission If Statement.

local players = game.Players:GetChildren()
local roundRunning = false
local Intermission = true

function teleportPlayers()
	for i,v in pairs(players) do
		HRP = v.Character.HumanoidRootPart
        	HRP.CFrame = CFrame.new(23.09, 11.473, 8.84)
	end
end

if Intermission == true then
    local intermissionHint = Instance.new("Hint", workspace)
    for i = 30, 0, -1 do
        intermissionHint.Text = "Intermission: "..i
        wait(1)
        if i == 0 then
            wait(1)
            intermissionHint:Destroy()
            Intermission = false
            roundRunning = true
	    teleportPlayers()
        end
    end
end


1 comment

0

It's working now! Thanks, don't see much of a different, but it's working. Thanks! :D

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