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.
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.