Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help teleporting the player slightly up?

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?

2 comments

0

LocalPlayer ONLY exists in LocalScripts. This causes you to need to remake your variables.

0

Thank you.

1 answer

✓ Accepted answer

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!

If I helped, please don't forget to accept my answer.

3 comments

0

Multiplying a CFrame is actually adding them. So the player will still shift up 2 studs however any collisions will not force the player to teleport up until no collision exists, unlike changing Position.

0

Just a quick question, if you were teleporting r15, what part would you use instead of torso?

0

I think it's still just Torso. If not, then maybe UpperTorso. Experiment. Sorry, I don't use R15 much.

This discussion is preserved as it was. New answers, comments, and votes are closed.