Before you say use a spawn location let me get you up to speed.
I basically have a level game and each level have a spawn point.
So when you when die in one level you went to another.
I then fixed that.
So now I need to make sure that they spawn at level 1.
So I made this script.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()
print("waited")
player.Character:WaitForChild("HumanoidRootPart").CFrame = game.workspace.Lobby.InvisiblePart.CFrame
print("Done!")
end)
It doesn’t work.
It prints the statements and has no error.
Z_lqify
(Kuzey)
June 11, 2021, 1:16pm
#2
Maybe try like this:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()
print("waited")
player.Character:MoveTo(game.workspace.Lobby.InvisiblePart.Position)
print("Done!")
end)
You need to yield a bit to overide the default spawn system. As seen from the documentation on character added:
wait() or stepped wait should work.
I believe this will be solution, found from the character added documentation Player.CharacterAdded .
local RunService = game:GetService("RunService")
-- Wait a brief moment before teleporting, as Roblox will teleport the
-- player to their designated SpawnLocation (which we will override)
RunService.Stepped:wait()
I also tested within studio should work, even a normal wait() works.
To debug add a CFrame changed property, it’ll see where and when the character has been teleported by the…
1 Like
Try this:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
char:WaitForChild("HumanoidRootPart").CFrame = game.Workspace.Lobby.InvisiblePart.CFrame
end)
end)
Add a print after you tp the player?
Edit: nvm theres already a solution
1 Like
This works but how could you make so it only does it when you 1st spawn in the game and not when you die?
If anyone has another solution that would be nice.
You haven’t even tried adding a yield to your script yet?
local part = script.Parent
game.Players.PlayerAdded:Connect(function(player)
local char = player.Character or player.CharacterAdded:Wait()
wait()--any yield should do
char.HumanoidRootPart.CFrame = part.CFrame
end)
2 Likes