Help with pickup script

I have a loot drop script that I have been trying to get to work in various ways over the past couple days. This is my newest attempt.

The item drops into the world, and its called Gem. Located in replicatedstorage.Tools.

I am trying to make a click detector script that when the gem is clicked, it adds the gold and then destroys the gem.

This is what I have so far. I have deleted and added a lot of different lines. I want to add a debounce, but dont think I should until the script is at least working. I am a newer scripter and might put it in the wrong spot.

local ClickDetector = script.Parent.ClickDetector
local sound = script.Parent.Pickup

ClickDetector.MouseClick:Connect(function(player)
	player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + script.Parent.Gold.Value
	sound:Play()	
	wait(1)
	script.Parent:Destroy()
	
end)

What is the problem though? What doesnt work specifically? Is there any errors in the output?

Well, I did some more testing and it seems to work fine for the gem, but not the gold piles. I am still trying to troubleshoot it. There is no error given on the gold piles. The click detector just does nothing.

1 Like

I found the error. It was a capital letter defining the sound.

Want to help me correctly debounce this? Ill make an attempt at it.

Here is debounced version.

local sound = script.Parent.Pickup -- Is that was an error?
local db = false -- Creating debounce variable
ClickDetector.MouseClick:Connect(function(player)
    if db then return end -- If not debounced then
    db = true -- It's debounced
    player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + script.Parent.Gold.Value
	sound:Play()	
	wait(1)
    db = false -- Now it isn't debounced.
	script.Parent:Destroy()
end)
1 Like

Where is this in the explorer? Could you screen shot it please.

Nice i just finished my attempt. This is what I had. And yes the pickup was the original error. lower case p.

Thanks for the help. Ill test these out.

Did I place my debounce in the wrong place?

local ClickDetector = script.Parent.ClickDetector
local sound = script.Parent.Gem
local debounce = false

ClickDetector.MouseClick:Connect(function(player)
	
	if debounce == false then
		
	player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + script.Parent.Gold.Value
	sound:Play()
	wait(1)
	script.Parent:Destroy()
		
	debounce = true	
	end
end)

Yes, you was need to place debounce = true right after if debounce == false then.

1 Like

Your going to have to set it back to true after awhile, so don’t forget that part, with a cool down

Ok thanks, I will try it like this.

local ClickDetector = script.Parent.ClickDetector
local sound = script.Parent.Gem
local debounce = false

ClickDetector.MouseClick:Connect(function(player)
	
	if debounce then return end
	
	debounce = true
	
	player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + script.Parent.Gold.Value
	sound:Play()
	wait(1)
	debounce = false
	script.Parent:Destroy()
			
end)

This is the script that I settled on. It works perfect.

I left out the debounce = false at the end, because the item gets destroyed anyways so there is no point.

local ClickDetector = script.Parent.ClickDetector
local sound = script.Parent.pickup
local debounce = false

ClickDetector.MouseClick:Connect(function(player)

	if debounce then return end

	debounce = true

	player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + script.Parent.Gold.Value
	sound:Play()
	wait(.5)
	script.Parent:Destroy()

end)
1 Like

Nevermind, that was a mistake of mine.