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

No errors so why isn't this 'spawn on load' script not working?

Asked by 5 years ago
Edited 5 years ago

I have put together a script from multiple sources and examples from around the net (that's the extent of my scripting ability so far) which, while likely a bit messy, should work in theory. I've used print() at all the key points to ensure that things are resolving as needed but the CFrame.new() just doesn't seem to want to fire. The script should run as a player connects, relocating them to the position of a previous checkpoint (models are named numerically and the primary part is also named the same hence the [progress][progress] path. The co-ordinates supplied come back accurate) Please, could some kind soul tell me why?

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
    local progress = player.leaderstats.Stage.Value
    local Root = char:FindFirstChild("HumanoidRootPart")
    Root.CFrame = CFrame.new(game.Workspace.checkPoints[progress][progress].Position + Vector3.new(0,3,0))
    end)
end)

I've tried a variety of other options including MoveTo which just made the player drift towards a nearby wall lol. Thanks in advance.

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

The problem is the game is trying to move the player before it finished loading. Try

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
    local progress = player.leaderstats.Stage.Value
    local Root = char:FindFirstChild("HumanoidRootPart")
repeat wait() until player.Character:FindFirstChild("Head") -- waits until players head is loaded before moving
    Root.CFrame = CFrame.new(game.Workspace.checkPoints[progress][progress].Position + Vector3.new(0,3,0))
    end)
end)
0
Figured it might be something like that but couldn't think how best to apply the wait() Works perfectly now, thanks so much! GrumpyTheDaddy 17 — 5y
0
Not a problem! :) WizyTheNinja 834 — 5y
Ad

Answer this question