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

New clickdetector wont replace the old one?

I edited a script and I made it where the item giver has a cooldown heres the script:

local PassId = 4835177
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local BloxyCola = ReplicatedStorage:WaitForChild("????? ???? ???")
local player = game.Players.LocalPlayer
local bloxy = workspace:WaitForChild("itemgiver1")

bloxy.ClickDetector.MouseClick:Connect(function(player)
	BloxyCola:Clone().Parent = player.Backpack
	script.Parent.Transparency=1
	script.Parent.ClickDetector:Destroy()
		for i = 10, 1, -1 do -- give it a 60 second cooldown and show the timer
            script.Parent.BillboardGui.TextBox.Text = tostring(i)
            wait(1)
	

		        end
		script.Parent.BillboardGui.TextBox.Text=(" ") --replaces text and resets everything back to normal
	script.Parent.Transparency=0
	 local ClickDetector = Instance.new("ClickDetector")
	ClickDetector.Parent = bloxy
	ClickDetector.MaxActivationDistance = 10

	

	
end)

but when the item spawns back i can't click it again, even though it shows the click cursor. what am i doing wrong here?

1 comment

0

.

1 answer

✓ Accepted answer

There is no reason to remove the clickdetector, you could instead use debounce. Debounce allows you to essentially deny all incoming requests from a connection until it is returned to false

local PassId = 4835177
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local BloxyCola = ReplicatedStorage:WaitForChild("????? ???? ???")
local player = game.Players.LocalPlayer
local bloxy = workspace:WaitForChild("itemgiver1")
local debounce = false

bloxy.ClickDetector.MouseClick:Connect(function(player)
	if not debounce then
		debounce = true -- stops any more clicks going through because of the line above this one
		BloxyCola:Clone().Parent = player.Backpack
		script.Parent.Transparency=1
		for i = 10, 1, -1 do -- give it a 60 second cooldown and show the timer
			script.Parent.BillboardGui.TextBox.Text = tostring(i)
			wait(1)
		end
		script.Parent.BillboardGui.TextBox.Text=(" ") --replaces text and resets everything back to normal
		script.Parent.Transparency = 0
		debounce = false -- allow the script to be run again
	end
end)

2 comments

0

thank you for teaching me about debounce but it wont turn off still. now the cursor wont show up

0

oh yeah i fixed it so it doesn't remove the line that you destroy it on

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