Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how do I use hit.Parent for a click detector?

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)

1 answer

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)

1 comment

1

Chili pretty much covers everything, though make sure that you are connecting the MouseClick to the ClickDetector in the Part, and not the actual Part.

This discussion is preserved as it was. New answers, comments, and votes are closed.