I made this script that opens a door when clicked with a ClickDetector, yet when I try and close it, the ClickDetector doesn’t detect anything?
Hierarchy:
Code:
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(1)
local door = script.Parent
local cd = door.Parent.ClickDetector
local isOpen = false
local open = {
CFrame = door.CFrame * CFrame.Angles(0,math.rad(-90),0)
}
local close = {
CFrame = door.CFrame * CFrame.Angles(0,0,0)
}
local doorOpen = TweenService:Create(door, Info, open)
local doorClose = TweenService:Create(door, Info, close)
cd.MouseClick:Connect(function()
print("pressed: "..door.Parent.Name)
if isOpen == false then
doorOpen:Play()
isOpen = true
else
doorClose:Play()
isOpen = false
end
end)
There are a few potential reasons why the ClickDetector might not be detecting clicks when you try to close the door:
Make sure that the ClickDetector is positioned correctly and is not obstructed by any other objects.
Check that the ClickDetector is enabled and is set to detect mouse clicks. You can do this by looking at the ClickDetector’s properties in the Properties window in Roblox Studio.
Make sure that the MouseClick event is properly connected to the doorClose:Play() function. You can do this by adding a print statement or a breakpoint to the event handler to see if it is being called.
Make sure that the doorClose tween is set up correctly and that the door is able to reach the target CFrame. You can check this by manually setting the door’s CFrame to the target CFrame and seeing if it moves correctly.
Make sure that there are no other scripts or events that might be interfering with the door’s behavior. This could include other MouseClick events, collision events, or update events that might be modifying the door’s CFrame or other properties.
If the ClickDetector is correctly positioned, enabled, and correctly connected to the doorClose:Play() function, and there are no other scripts or events interfering with the door’s behavior, then there may be a problem with the doorClose tween itself.
One potential issue could be that the target CFrame for the doorClose tween is not being set correctly. You can try manually setting the door’s CFrame to the target CFrame ( door.CFrame = close.CFrame ) to see if it moves correctly. If it does not move correctly, there may be a problem with the target CFrame itself or with the way that it is being calculated.
You could also try adding print statements or breakpoints to your code to see where the problem might be occurring. For example, you could try printing the door’s CFrame and the target CFrame before and after the doorClose:Play() function is called, to see if they are what you expect.
I think I’ve fixed it. The problem itself was the workspace (I used unions for some parts and since CollisionFidelity is set by default on “Default” I had to set it as “PreciseConvexDecomposition”).
All done now, was just a problem on my end, sorry!