I'm using click detectors for my game but I need to find the player to give the player "candies" whenever he clicks the pumpkin and I don't know how to achieve this
Here's my script :
script.Parent.MouseClick:connect(function(hit) local h = game.Players:findFirstChild(hit.Parent.Name) h.Candy.Value = h.Candy.Value +5 end)
The event MouseClick
has a parameter referred to as playerWhoClicked, so your local variable 'h' is not necessary. Instead, the following line of code could be used to add 5 to "Candy". I'll use 'hit' as that is how you are currently referencing the parameter. (Be sure that "Candy" is an IntValue object or NumberValue object.)
game.Players[hit]:FindFirstChild("Candy").Value = game.Players[hit]:FindFirstChild("Candy").Value + 5
You can read more on the MouseClick
event here: http://wiki.roblox.com/index.php?title=MouseClick_(Event)