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

Why is the Player Not Teleporting But The code runs?

Asked by 3 years ago
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?

0
It Turns out that I had to wait until the character was inserted into workspace cpcrafter365 0 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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

0
The variable "character" is the character of the player, so you shouldn't even need that Pupppy44 671 — 3y
0
or Next time it happens. Put A wait Function at the start and Write how Many Sec to wait HKprogram 48 — 3y
Ad

Answer this question