I was trying to make a script that teleported my character to a certain location after I spawn or re spawned , I made it a local script and placed it on Starter player scripts. It had no errors but it didn't work
player = game.Players.LocalPlayer char = player.character game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) char.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(14.3, 0.6, -105.4)) end) end)
This is what I have now.
If I run just the code
char.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(14.3, 0.6, -105.4))
It works but just once not when I respawn
You're using the CharacterAdded event, but you're not actually using the variable that returns alongside it (character), you're using (char) instead. Right now, you have an issue where you're potentially trying to access a character that does not exist yet. Try the following
player.CharacterAdded:connect(function(character) repeat wait() until character:FindFirstChild("HumanoidRootPart") character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(14.3, 0.6, -105.4)) end) end)