Trouble with getting player character

Hi everyone! I know is a basic question and i know there are a lot of answers about but i can’t find any for like an hour and i feel stupid right now.

I have a Part, this part has a ClickDetector

everytime i click i want to check if the player who clicked has on his hand a definite tool

i was actually using this script
local tool = player.Character:FindFirstChild("ToolName")

but actually i remembered that player will refer to the player class and not to workspace and it wasn’t working, i searched also on roblox official guide but the script

[Note from the official guide] “But from the server it’s fine to do this:”

 if player.Character then
-- do something
 end

https://developer.roblox.com/en-us/api-reference/property/Player/Character

I actually need to find this with ServerScript if possible:
1

How can i check that?

If you’re using a Click Detector, the click event passes a player variable.

So you could use this code in your server script

local clickDetector = script.Parent

clickDetector.MouseClick:Connect(function(player)
      print(player.Name, 'clicked the button!')
end)
3 Likes
ClickDetector.MouseClick:Connect(function(plr)
    local character = plr.Character --Get player character from click detector
end)
1 Like

Actually worked, i didn’t knew that (player) inside the function would be so much important, i have still a lot to learn, thanks both!