Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
Prioxis 673 Moderation Voter
9 years ago

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

Log in to vote
1
Answered by
Chili1924 150
9 years ago

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
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. SlickPwner 534 — 9y
Ad

Answer this question