✓ Accepted answer
local enabled = true
script.Parent.Touched:connect(function(hit)
if not enabled then return end
enabled = false
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.Backpack:WaitForChild("Hamburger")
if hit.Parent:FindFirstChild("Humanoid") then
player.leaderstats.Candy.Value = player.leaderstats.Candy.Value + 100
local hamburger = player.Backpack.Hamburger
script.Sound:Play()
hamburger:Destroy()
script.Parent:Destroy()
wait(1)
enabled = true
end
end)
Your script should be good to go, however I would suggest a couple modifications. As it is now, it will only give points to players who have their Hamburger tool Unequipped. Also the debounce will trigger regardless of the player actually owning a Hamburger or not (thus disabling the button for everyone for the given cooldown). Here is the script adapted to my suggested modifications:
local enabled = true
script.Parent.Touched:connect(function(hit)
if not enabled then return end
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player.Backpack:FindFirstChild("Hamburger") or hit.Parent:FindFirstChild("Hamburger") then
if not hit.Parent:FindFirstChild("Humanoid") then return end
enabled = false
player.leaderstats.Candy.Value = player.leaderstats.Candy.Value + 100
local hamburger = player.Backpack.Hamburger
script.Sound:Play()
hamburger:Destroy()
script.Parent:Destroy()
wait(1)
enabled = true
end
end)