Well, first off, you'll want to add this to your script --
if mouse.Target == nil then end
if mouse.Target ~= nil then
end
The problem with mouse.Target is that whenever it touches a nil value (for example, the skybox) it'll return a nil value.
Your line --
repeat wait() until game.Lighting.gate.Value == true
Means that none of the code under that will run until that value == true. In this case, you're just keeping the function from ending properly. It'll automatically loop, but as of now, at very high speeds.
You'll want to add a debounce to the script so that it can't activate too many times at once.
Also, the line repeat wait() until game.Lighting.gate.Value == true will want to be used inside of the gate itself. That means that the gate will not open until that value is true (assuming you have the open code below that line).
However, assuming you use the Changed event, you won't need that line. That line is mostly used for code that is already running, but you want to have a pause in order to wait for other things to happen before going forward. An example of the changed event in use is as follows --
game.Lighting.gamevalue.Value.Changed:connect(function(value)
end)
In case it isn't known, you'll want to use 2 scripts and a variable for this -- the local script that handles the part finding, the variable that detects changing, and the script in the gate that sees whenever the variable changes and initiates code accordingly.
That should be all, but if you continue to get errors, let me know and I can help out.
EDIT: This might also be in part to the fact that it's in a StarterGui instead of a tool. I'm not sure if mouse.Target will be able to get the local mouse if not inside of a tool. However, this is just a guess, and should only be considered if all else fails.
1 comment
if mouse.Target == nil then return end