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

How do you define a charcater/player?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.
0
Thanks for the answer! Baselistic 103 — 4y
0
No problem. I also added some more ways on how to do it. youtubemasterWOW 2741 — 4y
Ad

Answer this question