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

How do you define a charcater/player?

Hi! I am not that new to scripting but I still don't understand how to describe a player/character I learned that you can describe it by saying this:

local character = game.Players:GetPlayerFromCharacter()

But when I use it in events (such as Touched Event) It doesn't work

I want to understand.

1 answer

✓ Accepted answer

You have to put the character inside the brackets.

Example:

local Players = game:GetService("Players")

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
		local player = Players:GetPlayerFromCharacter(hit.Parent) -- Got the player.
	end
end)

hit.Parent is the character.

You can also define it by the PlayerAdded event:

game:GetService("Players").PlayerAdded:Connect(function(player) -- Got the player.

And also a ClickDetector:

ClickDetector.MouseClick:Connect(function(player) -- Got the player.

And finally, a remote event or function:

RemoteEvent.OnServerEvent:Connect(function(player) -- Got the player.

2 comments

0

Thanks for the answer!

0

No problem. I also added some more ways on how to do it.

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