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

How do I get a Player's character?

Asked by 10 years ago

I made a script but I keep getting a error in the output.

Workspace.Brick..Head.Script:4: attempt to index field 'Character' (a nil value)

script.Parent.Touched:connect(function(hit)
name = hit.Parent.Name
print(name.Character.userId)
end)

1 answer

Log in to vote
1
Answered by 10 years ago

Try this;

local debounce=false
script.Parent.Touched:connect(function(hit)
if not debounce then
debounce=true
plr=game.Players:GetPlayerFromCharacter(hit.Parent)
print(plr.Character.Name)
end
wait(2)
debounce=false
end)

I hope this helped!

Ad

Answer this question