What's the problem with this script? I am working on a Pokemon game an I need to make collectible items. This is the script for the rock item that is supposed to add 1 additional rock when clicked. The middle is not really important, I think. It works fine if I replace "function onClicked(part)" with "function onTouched(part)" and "script.Parent.ClickDetector.MouseClick:connect(onClicked)" with "script.Parent.Touched:connect(onTouched)", but that's not what I want to do with the script. I can provide more information if needed. Yes, I put ClickDetector inside the part. Thanks.
local amnt = 1
function onClicked(part)
local h = part.Parent:findFirstChild("Humanoid")
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local stats = thisplr:findFirstChild("stats")
if (stats~=nil) then
local score = stats:findFirstChild("Rock")
if (score~=nil) then
score.Value = score.Value + amnt
end
end
end
script.Parent:remove()
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

3 comments
Thanks, it works alright now!
How can I accept your answer? I don't see any button or something like that.
Sorry for the late reply. If you look to the right of my answer, you should see a little tick symbol and text saying "Accept Answer". Click that.