ClickDetectors not working properly

I have a game that uses ClickDetectors to open doors, I’ve used the same model a multitude of times I can confirm it works, however sometimes, it doesnt and looks like this.


(Supposed to be clickable)

Why does this happen? And no, nothing is obstructing it.

Is the ClickDetectors’ MaxActivationDistance property being edited at all? There might be some missing code that’s supposed to reset its’ MaxActivationDistance.

If you could provide some code, please do!

This script gets parented to every door:

wait(0.1)
script.ClickDetector.Parent = script.Parent

script.AutoOpen.Event:Connect(function(Player)
	local Ran = math.random(1,3)
	local Val1 = 1.221 / Ran
	local Val2 = 0.3 * Ran - 0.1
	script.Parent.Sound:Play()
	script.Parent.ClickDetector:Destroy()
	script.Parent.Sound.PlaybackSpeed = Val1
	game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(Val2, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {CFrame = script.Parent.Parent.DoorTween.CFrame}):Play()
end)

script.Parent.ClickDetector.MouseClick:Connect(function(Player)
	local Ran = math.random(1,3)
	local Val1 = 1.221 / Ran
	local Val2 = 1.221 * Ran - 0.1
	script.Parent.Sound:Play()
	script.Parent.ClickDetector:Destroy()
	script.Parent.Sound.PlaybackSpeed = Val1
	game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(Val2, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {CFrame = script.Parent.Parent.DoorTween.CFrame}):Play()
	game.ReplicatedStorage.Events.DoorOpened:Fire(script.Parent.Parent.Parent:GetAttribute('RoomID') + 1)
end)

script.Parent.ClickDetector:Destroy()

Looks like the ClickDetector is getting destroyed.

I would suggest using ClickDetector.MaxActivationDistance so the ClickDetector doesn’t show up when you don’t want it to.

ClickDetector.MaxActivationDistance = 16 -- Will show up for players within 16 studs.
ClickDetector.MaxActivationDistance = 0 -- Will not show up for any players.
1 Like

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