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

Script not working and no errors? No Idea why, everything seems fine.

Asked by 7 years ago

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

0
And this is a local script right? sammiya1 134 — 7y
0
put it instead in StarterCharacterScripts sammiya1 134 — 7y
0
Make sure you connect CharacterAdded function even if the player joins before the PlayerAdded event is connected. GoldenPhysics 474 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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)
0
As an aside, the reason I added line 2 was to ensure that the script waited until it found the RootPart within the humanoid - something I generally like doing if I'm unsure if the server will load things instantaneously. Nanami_Chiaki 15 — 7y
1
Then why not use WaitForChild? User#5423 17 — 7y
0
Still not working ;/ Zenistar 2 — 7y
Ad

Answer this question