Hello. For some reason, click detectors are not working! There are click detectors in the part, but it is not showing up! I added and tried the same model in a different game, and it works there. Any reason this is happening?
Click Detectors can only work if the person clicking on them is within range of the click detector, there’s a property in click detectors that can allow you to change the max amount distance a player has to be away from the part for them to be able to click on it.
Yes, I made sure to change that. I think it might be my camera settings, but I don’t know what.
What is the code you used to detect it being clicked?
Here is the script. This isn’t mine, I’m not the brightest at scripting.
db = false
door = false
script.Parent.DoorButton.ClickDetector.MouseClick:connect(function()
if not db then db = true
if not door then door = true
script.Parent.Door.Sound:play()
for i=0,15 do
script.Parent.Door.CFrame = script.Parent.Door.CFrame - Vector3.new(0,0.8,0)
wait()
end
script.Parent.Door.CFrame = script.Parent.Door.CFrame - Vector3.new(0,0.2,0)
db = false
elseif door then door = false
script.Parent.Door.Sound:play()
for i=0,15 do
script.Parent.Door.CFrame = script.Parent.Door.CFrame + Vector3.new(0,0.8,0)
wait()
end
script.Parent.Door.CFrame = script.Parent.Door.CFrame + Vector3.new(0,0.2,0)
db = false
end
end
end)
Are you getting any errors in your output?
Nope, I’m not. It works perfectly fine in other games too.
What happened is that you misplaced your debounce inside of another conditional statement.
Try this:
db = false
door = false
script.Parent.DoorButton.ClickDetector.MouseClick:connect(function()
if not db then
db = true
if not door then door = true
script.Parent.Door.Sound:play()
for i=0,15 do
script.Parent.Door.CFrame = script.Parent.Door.CFrame - Vector3.new(0,0.8,0)
wait()
end
script.Parent.Door.CFrame = script.Parent.Door.CFrame - Vector3.new(0,0.2,0)
db = false
elseif door then door = false
script.Parent.Door.Sound:play()
for i=0,15 do
script.Parent.Door.CFrame = script.Parent.Door.CFrame + Vector3.new(0,0.8,0)
wait()
end
script.Parent.Door.CFrame = script.Parent.Door.CFrame + Vector3.new(0,0.2,0)
end
db = false
end
end)
That didn’t work. Could it be that I set the camera to scriptable? I don’t know why that would be but…
I think the issue may have to do with the fact it’s adding a CFrame and a Vector3, so maybe if you changed all the things in @Clueless_Brick’s reply that said “CFrame” with “Position” then it might work.
I am testing it in-studio and it is functionally working properly. Do you have you click detector inside your button? What does the output say?
Output is fine, but I figured out which script is causing click detectors not to work. It the script that makes my camera part work. Do you think you can fix it?
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
repeat wait()
Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace.CameraPart.CFrame
I recreated my game then added the scripts back one by one. Once I added that it stopped functioning.
You can reduce repeating by doing bool = not bool, and use local variables. And please don’t use the deprecated connect, instead use Connect, and also sound:play(), use :Play() please.
Edit: Oh yeah, and please DRY your code, add the door part to a variable. And I totally forgot that you can use += and -=.
Here’s the fixed code:
local doorPart = script.Parent.Door
local db = false
local door = false
script.Parent.DoorButton.ClickDetector.MouseClick:Connect(function()
if not db then
db = true
doorPart.Sound:Play()
if door then
for i=0,15 do
doorPart.CFrame += Vector3.new(0,0.8,0)
wait()
end
doorPart.CFrame += Vector3.new(0,0.2,0)
else
for i=0,15 do
doorPart.CFrame -=Vector3.new(0,0.8,0)
wait()
end
doorPart.CFrame -= Vector3.new(0,0.2,0)
end
door = not door
db = false
end
end)
Thank you for correcting me. I was just skimming through the code and didn’t thoroughly see the deprecated terms that OP typed down. OP, consider this as your solution.
Yeah, but it didn’t work. The first script I sent isn’t the problem. It is my camera script. This is it:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
repeat wait()
Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace.CameraPart.CFrame
Why is the CameraType being set to scriptable? Is there some context behind it that you’re able to share with us?
At any rate, if you really need the camera to be Scriptable, then Click Detector might not work too well and you should consider other options, such as getting the mouse through UserInputService.
Yeah, if it isn’t set to scriptable, then my camera system wouldn’t work. I forgot to mention that.
I tested clicking a ClickDetector with CameraType set to Scriptable, I can still click on it without any problems though.
Did you use your humanoid as a camera? Because I’m using a part.