So I have this one script that controls all the buy buttons in this model, but whenever you touch one of the buy buttons, it's debounce affects all buttons, rather than the one you touched. I don't really know how to fix, and I would love to figure out how to.
local debounce = false
local cooldowninterval = 2
for _, button in pairs(script.Parent:GetChildren()) do
if button:FindFirstChild("Head") then
button:FindFirstChild("Head").Touched:Connect(function(hit)
if debounce then
return
end
debounce = true
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player and player.Character then
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid and humanoid.Health > 0 then
local leaderstats = player:FindFirstChild("leaderstats")
local cash = leaderstats:FindFirstChild("Cash")
if leaderstats and cash then
local item = button:FindFirstChild("Item")
local cost = button:FindFirstChild("Cost")
if cash.Value >= cost.Value then
cash.Value = cash.Value - cost.Value
local itemclone = game:GetService("ServerStorage")[item.Value]:Clone()
itemclone.Parent = player.Backpack
end
end
end
end
wait(cooldowninterval)
debounce = false
end)
end
end

2 comments
It's a part...
^ then I have a question...game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) <-- that means that all the players from the game would need to touch the brick at the same time????? ._.