I am making diamonds to collect on my map! They regen and give points perfectly, but they do not make a sound when collected. When I try to put in a sound, the script breaks! I also noticed other scripts will have the sound looping so if they stay in the spot where it regenerates, it plays the sound constantly.
I would like it to play the sound only when the item is not transparent. That, or only allow the sound to function every 7 seconds (the time it regens) whatever is easier :)
Here is my script without trying to add in any sounds -
(Please let me know what and where I need to put it! Thank you so much I appreciate it a ton!)
waittime = 7 -- Time Between each hit
amnt = 10 --how much you get for it
function onTouched(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("leaderstats")
if (stats~=nil) then
local score = stats:findFirstChild("Money")
if (score~=nil) then
score.Value = score.Value + amnt
end
end
end
script.Parent.Transparency = 1
script.Disabled = true
wait(waittime)
script.Parent.Transparency = 0
script.Disabled = false
end
end
script.Parent.Touched:connect(onTouched)

1 comment
It worked, thank you so much! You are amazing! Thank you for explaining to me how it works as well!