Any way to locally disable a clickdetector?

I’m trying to make a box delivery job and I want to prevent the player from starting the job right after they finished it, I want to make the clickdetector have a cooldown but only for the player who clicked it? Is it possible?

You could add a debounce. What does your current script look like?

1 Like

You could just reference the ClickDetector from the client side, then change the MaxActivationDistance property to 0 when it’s first clicked to prevent it from being clicked again

Then after a while you can set back the property to 32 when the job is finished:

local ClickDetector = workspace.Part.ClickDetector --Thingy or where you want it to be

ClickDetector.MouseClick:Connect(function()
    ClickDetector.MaxActivationDistance = 0
    wait(600)
    ClickDetector.MaxActivationDistance = 32
end)
3 Likes

It is possible.
There’s events in ClickDetector that is related to mouse buttons that will give you the things you need.

ClickDetector.MouseClick
ClickDetector.MouseHoverEnter
ClickDetector.RightMouseClick
ClickDetector.MouseHoverLeave

When you connect a function to those events, the event will give you the instance of the player who has clicked/hovered/etc.

Note: it would not be wise to do this locally, but rather do it on the server since it is simpler and better. If it’s local then exploiters can just revert the changes the script made.

1 Like

Use a table debounce to have player sided cooldowns

Example

local detector = script.Parent.ClickDetector

local debPlayers = {}

detector.MouseClick:Connect(function(plr)
	if debPlayers[plr.Name] then return end
	debPlayers[plr.Name] = true
	--Code
	wait(1)
	debPlayers[plr.Name] = nil
end)

If one player clicks the detector, the cooldown will only impact them, others can still click it even if the cooldown is continuing. Hopefully this should be what is needed

1 Like

I don’t know too much about debounce but I’m guessing it’s like a player-sided cooldown [Correct me if i’m wrong.]
But here’s my script:

script.Parent.MouseClick:Connect(function(player)
	script.Parent.MaxActivationDistance = 0
	local toolToGive = game.ReplicatedStorage.Box
	
	local backpackTool = player.Backpack:FindFirstChidl(toolToGive.Name) or player.Character:FindFirstChild(toolToGive.Name)
	
	if not backpackTool then
		toolToGive:Clone().Parent = player.Backpack
	end
	wait(250)
	script.Parent.MaxActivationDistance = 10
end)

You can do something like to make the debounce only affect who clicked

local playerdebs = {}

script.Parent.MouseClick:Connect(function(player)
	if playerdebs[player.Name] then return end
	playerdebs[player.Name] = true
	--script.Parent.MaxActivationDistance = 0
	local toolToGive = game.ReplicatedStorage.Box
	
	local backpackTool = player.Backpack:FindFirstChidl(toolToGive.Name) or player.Character:FindFirstChild(toolToGive.Name)
	
	if not backpackTool then
		toolToGive:Clone().Parent = player.Backpack
	end
	wait(250)
	playerdebs[player.Name] = nil
	--cript.Parent.MaxActivationDistance = 10
end)
2 Likes