Hello. I am currently trying to develop a door that can be locked with the enablement of just one simple value. I've tried a lot of things and after some experimenting I've realised that the "Handler" script is doing absolutely nothing at all. The following script is supposed to change something when the value in the model is changed. Here is the code.
local Closed = script.Parent.Closed.Value local Closed = true -- This line is removed after the 1st edit pretend like it isnt here if Closed == true then --do this if closed true else --do this if closed false end
This might just be a small issue but I am not a genius when it comes to scripting, help greatly apprecieated.
[EDIT] : Due to some confusion I will be clearing up some things. Line 2 seems to be totally useless so I will be removing it. The script is not a Local Script, its a regular one. Let me explain what exactly I need from this script. I want that whenever a button is pressed In-Game the value "closed" will be changed. This Script is then supposed to change something judging on whenever the Value is changed to true or false. I've implemented a Button into my game that LITERALLY changes the Value in question when its clicked. And this script does nothing, altough its supposed to "do this if closed true". Instead it sticks to whatever the Value was when the test of the game was started.
Hi, good afternoon.
First of all, there are a few errors in your code. The variable "Closed" is used twice. You have already defined Closed, so no need to define it again. Therefore, you may make this change.
local Closed = script.Parent.Closed.Value Closed = true
The main problem with your code, however, is that you are using a value. The script does not detect if the value is changed. There is a function to detect this change.
:GetPropertyChanedSignal()
When using :GetPropertyChanedSignal()
, we must first define the object which we'll be looking inside for a change. In this case, it is the BoolValue
"Closed." Inside the parenthesis, we must show which property of the BoolValue
we're looking for a change in as well. In this case, it's Closed.Value
We must make some variable changes to account for this. Here is just the variable code and the first line accounting for change.
local Closed = script.Parent.Closed Closed.Value = true
Notice how instead of just Closed, I follow it by .Value
to account for the variable change.
Now, we can use the function. Here is how it is used.
local Closed = script.Parent.Closed Closed.Value = true Closed:GetPropertyChangedSignal("Value"):Connect(function() if Closed.Value == true then --Code that will run when the value is true else --Code that will run when the value is false end end)
This should work. (It has been tested)
Hope this helps!
Not too sure what the problem is here, but I think I might have a solution.
local Closed = script.Parent.Closed.Value --local Closed = true -- Not too sure what the point of this line is, so I'll just leave it out of the code. local Sound = workspace.LockSound -- Make a Sound in the Workspace called LockSound. Make sure you give it an ID. local MouseClick = script.Parent -- Set your script's parent to a ClickDetector inside your door part. MouseClick.MouseClick:Connect(function() if Closed == true then Sound:Play() print("Locked...") --do this if closed true else print("Unlocked!") --do this if closed false end end)
Again, not sure what the problem is, but I hope I helped. Bye!