So I’m making a shop system, and it prints 5 times. Everything else is removing 5 times as well, like when I buy 1 $20 dollar shirt, it removes $100 dollars from my leaderstats, and it gives me 5 skirts. Can you please help?
Script:
remotes.BuyStock.OnServerEvent:Connect(function(player, item, amount)
if player and item and amount then
print(player.Name.." is trying to buy "..amount.." "..item.Name)
if stockItems:FindFirstChild(item.Name, true) then
local leaderstats = player:WaitForChild("leaderstats")
local itemsInStock = player:WaitForChild("ItemsInStock")
local price = item:WaitForChild("Price")
if leaderstats and itemsInStock then
if leaderstats.Coins.Value >= (amount * price.Value) then
leaderstats.Coins.Value -= (amount * price.Value)
itemsInStock[item.Name].Value += amount
end
end
end
end
end)
Prints:
15:15:09.351 ▶ catxkdb is trying to buy 1 Skirt (x5) - Server - Main:9
15:15:14.584 ▶ catxkdb is trying to buy 2 Skirt (x5) - Server - Main:9
15:15:16.117 ▶ catxkdb is trying to buy 3 Skirt (x5) - Server - Main:9
15:15:17.250 ▶ catxkdb is trying to buy 4 Skirt (x5) - Server - Main:9
local db = false
if selectedTemp ~= nil then
if db == false and db ~= true then
db = true
local item = game.ReplicatedStorage.StockItems[selectedTemp.Name]
local result = game.ReplicatedStorage.Remotes.BuyStock:FireServer(item, amnt.Value)
wait(.2)
db = false
end
end
local db = false
if selectedTemp ~= nil then
if db == false and db ~= true then
db = true
local item = game.ReplicatedStorage.StockItems[selectedTemp.Name]
local result = game.ReplicatedStorage.Remotes.BuyStock:FireServer(item, amnt.Value)
wait(.2)
db = false
end
end
I think it should be something like this, as if you put debounce inside the script, it will automatically set the debounce to false the whole time, as it runs, so remain it outside of the function.