My debounce is not working after following the format of serveral other posts.
When the script is run, the prints are printing in a “1” “2” “1” “2” order.
local db = false
script.Parent.Parent.Parent.Info.Equip.MouseButton1Click:Connect(function()
if db == false then
db = true
print("1")
game.ReplicatedStorage.Sounds.Click:Play()
if script.Parent.Parent.Parent.Info.Equip.Text == "Equip" then
game.ReplicatedStorage.Remotes.Equip:FireServer(game.Players.LocalPlayer, script.Parent.Name)
elseif script.Parent.Parent.Parent.Info.Equip.Text == "Unequip" then
game.ReplicatedStorage.Remotes.Equip:FireServer(game.Players.LocalPlayer, script.Parent.Name, "Un")
end
print("2")
wait(5)
db = false
end
end)
This is the whole script, and the only debounce is in the problematic area.
script.Parent.TextButton.MouseButton1Click:Connect(function()
game.ReplicatedStorage.Sounds.Click:Play()
if game.ReplicatedStorage.Mobs.Spawnable:FindFirstChild(script.Parent.Name) then
local info = script.Parent.Parent.Parent.Info
local tower = game.ReplicatedStorage.Mobs.Spawnable:FindFirstChild(script.Parent.Name)
info.Damage.Text = tower["0"].Damage.Value
info.Range.Text = tower["0"].RangeValue.Value
info.Firerate.Text =tower["0"].Firerate.Value
info.NameText.Text = tower.Name
end
end)
local db = false
script.Parent.Parent.Parent.Info.Equip.MouseButton1Click:Connect(function()
if db == false then
db = true
print("1")
game.ReplicatedStorage.Sounds.Click:Play()
if script.Parent.Parent.Parent.Info.Equip.Text == "Equip" then
game.ReplicatedStorage.Remotes.Equip:FireServer(game.Players.LocalPlayer, script.Parent.Name)
elseif script.Parent.Parent.Parent.Info.Equip.Text == "Unequip" then
game.ReplicatedStorage.Remotes.Equip:FireServer(game.Players.LocalPlayer, script.Parent.Name, "Un")
end
print("2")
wait(5)
db = false
end
end)
What do you want to do, that a Player cant click the Button for 5 Seconds? I tried it it worked or is the script running the MouseButton1Event two times?
Could u send the Place? Do you have more other scripts there what is connecting to this script? Do you accidently have the same Script in another Localscript?
The outputs are coming from the same script, ruling out a duplicate script. This combined with being a simple mousebutton1 event rules out another script being connected to it.
I figured out the problem; it was my bad
When the game started a gui with script in was cloned, making the event fire twice.
Thank you for the help though.