Reputation: 25
For some reason my Click Detector that I had put inside of my Local Script / Script (tried both) doesn't detect when it's clicked on. Does anyone know what causes this? Code:
local ts = game:GetService("TweenService")
local labdoor = script.Parent.Parent["Laboratory door"]
local cframe = labdoor.CFrame
local goal = {Position = Vector3.new(484.15, 67.44, 188.125)}
local tweeninfo = TweenInfo.new(1)
local tween = ts:Create(labdoor, tweeninfo, goal)
script.Parent.MouseClick:Connect(function(plr)
print(plr.Name, " pressed the button!")
tween:Play()
end)
I tried putting it both inside and outside of click detector, server sided and client sided script, but they don't seem to do anything.
Now, the more correct question to ask, is why it works in a brand new place, but not in the one that I'm currently working on. The ClickDetector
works on the same door, same everything, I just straight up can copy and paste from 1 experience to other, and it'll work. ClickDetector
parent is the part that is the button, and the scripts parent is the ClickDetector
.
Upvotes: 0
Views: 130
Reputation: 61
While ClickDetectors work in both the client (local scripts) and the server (normal scripts), it is important to note that local scripts do not run when they are parented to Workspace. They will either need to be in PlayerGui
or PlayerScripts
, which can be done through parenting them to StarterPlayeScripts
or StarterGui
. Generally, client-sided scripts are used for things such as animations but for this case (opening a door), doing it on the server is fine.
Note: Having doors open on the server is still bad, and in the ideal case, you would want to register the MouseClick
on the server, and then fire a remote event to all clients to tween the door open. However, doing the tween on the server is fine too, albeit more inefficient.
Anyway, your script accesses the click detector through script.Parent
, meaning your script will need to be placed directly inside the click detector. And, because local scripts do not run when inside workspace (and because you want all players to see the door opening), this will need to be a regular script.
If this is a regular script and it is right inside the click detector, it will work. Make sure your click detector is right inside the part that is to be clicked.
Upvotes: 0