Currently, I am trying to teleport the player up by 2 studs. So, I made this script.
name = game.Players.LocalPlayer.Name char = game.Workspace:FindFirstChild(name) X = char.Torso.Position.X Y = char.Torso.Position.Y Z = char.Torso.Position.Z game:GetService('Players').PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() game.Workspace.Player.Torso.CFrame = CFrame.new(Vector3.new(X,Y+2,Z)) end) end) end)
I figured that lines 1 and 2 would select the player, lines 4, 5, and 6 would state the X, Y, and Z positions of the torso. The function would simply move the torso up by 2 studs. I however get this error.
**20:34:09.172 - Workspace.Ragdolls.Script:1: attempt to index field 'LocalPlayer' (a nil value)
Help?
LocalPlayer
only works in LocalScripts
. You can get the player through the PlayerAdded
event so the top part of your script is the main problem, and unnecessary. Also on line 11, we don't need to look for the character because the CharacterAdded
function does that for us. The final thing is I would suggest simply Multiplying the character's torso CFrame
by CFrame.new(0,2,0)
instead of adding two. It will cause the same effect and make your script a little cleaner.
-- Regular Script game:GetService('Players').PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) character:WaitForChild("Humanoid").Died:Connect(function() character.Torso.CFrame = character.Torso.CFrame * CFrame.new(0,2,0) end) end) end)
Good Luck!