Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this award multiple items?

01 debounce = false 02

03 script.Parent.MouseEnter:connect(function(enter) 04 script.Parent.BorderSizePixel = 3 05 script.Parent.MouseButton1Click:connect(function(onClick) 06 for i, player in pairs(game.Players:GetChildren()) do 07 if player.Points.Value >= 100 then 08 player.Points.Value = player.Points.Value - 100 09 if debounce == false then 10 debounce = true 11 local ks = game:GetService("ReplicatedStorage").Swords.KnightsSword 12 ks:Clone().Parent = player.Backpack 13 ks:Clone().Parent = player.StarterGear 14 debounce = false 15 end 16 end 17 end 18 end) 19 end) I have tried many different ways to stop this but nothing works. I have it set to if the player has 100 or more points then give them an item, but it dosent just give them the item and takes 100 away, sometimes it gives you 2 or 3 of the item and charging 200, or 300. Is there a way to prevent that so it the sword is only awarded ONCE and they cant pruchase another for 10 seconds.

1 comment

1

Put it in a code block please.

1 answer

This is the srcipt in a code block:

debounce = false
script.Parent.MouseEnter:connect(function(enter)
script.Parent.BorderSizePixel = 3 
script.Parent.MouseButton1Click:connect(function(onClick) 
for i, player in pairs(game.Players:GetChildren()) do 
if player.Points.Value >= 100 then 
player.Points.Value = player.Points.Value - 100 
if debounce == false then 
debounce = true 
 local ks = game:GetService("ReplicatedStorage").Swords.KnightsSword    ks:Clone().Parent = player.Backpack 
 ks:Clone().Parent = player.StarterGear 
 debounce = false 
 end 
 end 
 end 
 end) 
 end) 

This discussion is preserved as it was. New answers, comments, and votes are closed.