Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Why is the Player Not Teleporting But The code runs?

Asked by 12 days 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 — 12d

1 answer

Log in to vote
0
Answered by 12 days 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 471 — 12d
0
or Next time it happens. Put A wait Function at the start and Write how Many Sec to wait HKprogram 2 — 12d
Ad

Answer this question