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

How to get a players character without "attempted to index nil with 'Character'"?

This is really annoying me. I was trying to make the player jump in a script when they clicked a button, but output just says "attempt to index nil with 'Character'". It's in a server side script, and the local player had already been addressed and everything. I have tried this:

lp = game.Players.LocalPlayer
lpc = lp.Character

and this:

lpc = game.Players.LocalPlayer.Character

also this...

lp = game.Players.LocalPlayer
lpc = game.Workspace:FindFirstChild(lp.Name)

this was the code for the jump... (inside of a function)

lpc.Humanoid.Jump = true

Why does this keep happening? Why does it work in scripts other than mine? I'm only getting errors for this part of the script. If you need me to release the whole script, I will.

2 comments

0

You can't call localplayer from a server script. Is the button a gui or a click detector?

0

clickdetector

2 answers

✓ Accepted answer

Clickdetectors have an argument in the MouseClick event that passes the player that clicked it. From there you can call their character and humanoid.

--server script

Part = script.Parent

function onClick(plr)
 plr.Character.Humanoid.Jump = true
end

Part.ClickDetector.MouseClick:Connect(onClick)

You cannot use the local player in a server script - only in a local script.

To get around this, you can use remote events.

Create a remote event in the workspace with a server script listening to it. Have a button that fires the event on the client, and you've got yourself a working jump button.

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