How to get player on character on workspace or humanoidrootpart

  1. I want to make simple vote system. There is a boxes in characters humanoidrootpart and on click they adding +1 vote to box’s parent.

  2. There is no error but im pretty sure that I can’t get player from character or humanoidrootpart

  3. I tried part.Parent.Parent:GetPlayerFromCharacter() , plr:GetPlayerFromCharacter() , plr.Character:GetPlayerFromCharacter()

 local part = script.Parent.Parent
local clickdetector = script.Parent


clickdetector.MouseClick:Connect(function(plr)
	local player = part.Parent.Parent:GetPlayerFromCharacter()
	if plr:WaitForChild("Folder").Voted.Value == false then
		plr:WaitForChild("Folder").Voted.Value = true
		player:WaitForChild("Folder").Vote.Value += 1
		
		
	end
end)
3 Likes

ClickDetectors return the player instance, so there’s no need for GetPlayerFromCharacter. You can remove the line defining the player variable and set all instances of player to plr.

Whoops. Misunderstood. Sorry!

1 Like

But plr is who clicked to box and player is who has box

GetPlayerFromCharacter() is a method of Players Service.

You can see it here:

3 Likes

So I can’t reach to player from character in workspace?

when a clickdetector is clicked the plr is the actual player not the character. If u want to find the character use plr.Character. The GetPlayerFromCharacter function works like this

game.Players:GetPlayerFromCharacter(the player character)
1 Like

If you have the player’s character, you can just use the Players Service to get the player by his character. But I don’t know if it’s your case (I guess not), do u already have the player’s character model who has been voted?

2 Likes

I have player who is voted and a character who had box for vote. Im a try player service since I didn’t try it

1 Like

Yes it’s worked thank you. I changed to this

local playerservice = game:GetService("Players")
local player = playerservice:GetPlayerFromCharacter(part.Parent.Parent)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.