Help with debounces

Hello DevFourm, I need to add a debouce on this ServerScript. Could Someone help me?

local Event = game.ReplicatedStorage.ItemSpawn
local Item = game.ReplicatedStorage.Items.Cube
local Player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent
local RootPart = Player.Character:WaitForChild("HumanoidRootPart")

script.Parent.MouseButton1Click:Connect(function()
	Event.OnServerEvent:Connect(function(plr, position)
		local ItemClone = Item:Clone()
		ItemClone.Parent = workspace
		ItemClone.Position = position
	end)
end)

This is why I need a debounce:

It should be spawning once per click but it spawns more than once. I’m not familiar with denounces so could someone add them for me?

Thank you :slight_smile:

You’re connecting the event, but never removing it when finished. Change Connect to Once and that should fix it.

Thank you, such a simple fix lol. :slight_smile:

1 Like
local Event = game.ReplicatedStorage.ItemSpawn
local Item = game.ReplicatedStorage.Items.Cube

Event.OnServerEvent:Connect(function(plr, position)
	local ItemClone = Item:Clone()
	ItemClone.Parent = workspace
	ItemClone.Position = position
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.