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.
There is no error but im pretty sure that I can’t get player from character or humanoidrootpart
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)
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.
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)
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?