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

Why is the Player Not Teleporting But The code runs?

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		local char = plr.character or character
		print(char.Name)
		if MiniGameIsPlaying.Value == false then
			if game.Workspace:FindFirstChild("MainSpawn")then
				local MainIsland = game.Workspace:FindFirstChild("MainSpawn")
				local spawns = MainIsland.Spawns
				local randomSpawnNum = math.random(1,#spawns:GetChildren())
				char:WaitForChild("HumanoidRootPart").CFrame = spawns:GetChildren()[randomSpawnNum].CFrame
				warn("YES")
			end
		elseif MiniGameIsPlaying.Value == true then
			if game.Workspace:FindFirstChild("SpecRoom")then
				local MainIsland = game.Workspace:FindFirstChild("SpecRoom")
				local spawns = MainIsland.Spawns
				local randomSpawnNum = math.random(1,#spawns:GetChildren())
				char:FindFirstChild("HumanoidRootPart").CFrame = spawns:GetChildren()[randomSpawnNum].CFrame
				warn("NO")
			end	
		end
	end)
end)

It warns YES and NO but it dosen't teleport, Can someone help me?

1 comment

0

It Turns out that I had to wait until the character was inserted into workspace

1 answer

It Turns out that I had to wait until the character was inserted into workspace

it turns out I had to replace the line:

local char = plr.character or character

With:

local char = game.Workspace:WaitForChild(character.Name) or character

2 comments

0

The variable "character" is the character of the player, so you shouldn't even need that

0

or Next time it happens. Put A wait Function at the start and Write how Many Sec to wait

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