What do you want to achieve?
A selling system that works!
What is the issue?
The issue is when you go to sell the debounce doesn’t work and spams the sound I added in!
What solutions have you tried so far?
Finding a solution
script.Parent.Touched:Connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(h.Parent)
local sound = script.Parent.CoinSound
local debounce = false
if debounce == false then
debounce = true
if player then
local leaderstats = player:WaitForChild("leaderstats")
local currency = leaderstats.Coins
local selling = leaderstats.Strength
if selling.Value > 0 then
sound:Play()
wait(0.3)
currency.Value = currency.Value + selling.Value
selling.Value = 0
player.Level.Exp.Value = player.Level.Exp.Value + 1
debounce = true
end
end
end
end
end)
Basically I want it so if you step on a part it sells currency and then you have to step off the part and step back on it to sell again instead of staying on the part and keep selling currency. If you do not know what I mean its basically a selling place for a simulator.
script.Parent.Touched:Connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(h.Parent)
local sound = script.Parent.CoinSound
local debounce = false
if debounce == false then
if player then
local leaderstats = player:WaitForChild("leaderstats")
local currency = leaderstats.Coins
local selling = leaderstats.Strength
if selling.Value > 0 then
debounce = true
sound:Play()
wait(0.3)
currency.Value = currency.Value + selling.Value
selling.Value = 0
player.Level.Exp.Value = player.Level.Exp.Value + 1
debounce = false
end
end
end
end
end)
local debounce = false
script.Parent.Touched:Connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(h.Parent)
local sound = script.Parent.CoinSound
if debounce == false then
if player then
local leaderstats = player:WaitForChild("leaderstats")
local currency = leaderstats.Coins
local selling = leaderstats.Strength
if selling.Value > 0 then
debounce = true
sound:Play()
wait(0.3)
currency.Value = currency.Value + selling.Value
selling.Value = 0
player.Level.Exp.Value = player.Level.Exp.Value + 1
debounce = false
end
end
end
end
end)
local debounce = false
script.Parent.Touched:Connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(h.Parent)
local sound = script.Parent.CoinSound
if debounce then
debounce = false
task.wait(5)
return
end
if player then
local leaderstats = player:WaitForChild("leaderstats")
local currency = leaderstats.Coins
local selling = leaderstats.Strength
if selling.Value > 0 then
debounce = true
sound:Play()
task.wait(0.3)
currency.Value = currency.Value + selling.Value
selling.Value = 0
player.Level.Exp.Value = player.Level.Exp.Value + 1
end
end
end
end)
Change task.wait(5) to whatever preferred length of time.