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

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

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

✓ Accepted answer

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)

2 comments

0

Figured it might be something like that but couldn't think how best to apply the wait() Works perfectly now, thanks so much!

0

Not a problem! :)

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