I know I have been posting a lot frequently, but that is because I am a bit rusty in scripting, after taking a long break.
Now, to the point.
Below is the script that I am using to spawn the player at a certain point. Also below is a video on what happens when the player loads in.
The player does not spawn at the location.
Script
for _, descendant in pairs(spawns:GetDescendants()) do
-- Loops through the available spawns
if descendant:IsA("NumberValue") then
if descendant.Value == lvl.Value then
firstSpawn = descendant.Parent
-- Assign firstSpawn to the descendants parent (aka the first checkpoint)
end
end
end
player.CharacterAdded:Connect(function(characterModel)
wait(0.01)
print("done")
-- Make them spawn at the starting point
characterModel.HumanoidRootPart.CFrame = CFrame.new(firstSpawn.Position + Vector3.new(0,5,0))
end)
Trying to move the character right when it’s created is kind of a nightmare. It really doesn’t like to work.
Here’s what I generally do to move it:
if not character:IsDescendantOf(Workspace) then
character.AncestryChanged:Wait()
end
task.wait()
character.HumanoidRootPart.CFrame = CFrame.new() -- Set to CFrame
I believe this has something to do with the character being client sided. If anyone has a better way of doing this please DM me.
This is not a problem. If you’d like to learn more, here is the API for the functions and operator definitions used:
CFrame.new ( Vector3 pos )
Returns a CFrame with no rotation with the position of the provided Vector3.
Vector3Vector3 + Vector3
Returns a new Vector3 with each component of the second added to the corresponding component of the first.
I suggest waiting for a cframe change before setting it as when you spawn in your cframe is changed. Here:
-- Loops through the available spawns
if descendant:IsA("NumberValue") then
if descendant.Value == lvl.Value then
firstSpawn = descendant.Parent
-- Assign firstSpawn to the descendants parent (aka the first checkpoint)
end
end
end
player.CharacterAdded:Connect(function(characterModel)
print("done")
-- Make them spawn at the starting point
local rootPart = characterModel:WaitForChild("HumanoidRootPart")
rootPart:GetPropertyChangedSignal("CFrame"):Wait()
task.wait()
characterModel.HumanoidRootPart.CFrame = CFrame.new(firstSpawn.Position + Vector3.new(0,5,0))
end)