You can write your topic however you want, but you need to answer these questions:
**What do you want to achieve? Create a Button for a Tycoon
**What is the issue? Money gets removed 2 times
**What solutions have you tried so far? changed code with a waiting task.
So basiccly I am creating a Tycoon. But when walkin over a button the amount of money which gets removed is 2x the amount the button cost and i dont know why or how I can fix it.
Ty for the help
v.Button.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if values.OwnerValue.Value == player then
if v.Button.CanCollide == true then
if player:FindFirstChild(“leaderstats”).Cash.Value >= v.Price.Value then
player.leaderstats.Cash.Value -= v.Price.Value
objects[v.Object.Value].Parent = tycoon.Purchases
playSound(v, audio.ButtonSound.SoundId)
v:Destroy()
else
playSound(v, audio.ErrorSound.SoundId)
end
end
end
end
end)
local HasTouched = false
v.Button.Touched:Connect(function(hit)
if HasTouched == false then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if values.OwnerValue.Value == player then
if v.Button.CanCollide == true then
if player:FindFirstChild(“leaderstats”).Cash.Value >= v.Price.Value then
player.leaderstats.Cash.Value -= v.Price.Value
objects[v.Object.Value].Parent = tycoon.Purchases
playSound(v, audio.ButtonSound.SoundId)
HasTouched = true
task.wait(1)
HasTouched = false
v:Destroy()
else
playSound(v, audio.ErrorSound.SoundId)
end
end
end
end
end
end)
i added a debounce to your code try this and see if it works
first of all check if you have 1 button you may have cloned the button 2 times accidentally
if that didnot work try adding the event to a variable and disconnect when done
like
local event = v.Button.Touched:Connect(function(hit)
-- before subtracting player cash do this
event:Disconnect()
studio isnot opening for me rn the code may have errors
i think that is happening because when the player touchs the button it fires more than once because each of the player character objects like Left Leg and Right Leg will fire so the event will fire 2 times so if the player have like 200 cash and the button purchase cost 100 it will subtract his cash 2 times because the event was called 2 times because the player have 2 legs but if the player have like 150 cash then it will only subtract his cash 1 time ig
english isnot my main language this maynot be clear