I am attempting to set a bool value to true, simple as that, but I keep getting an error claiming that said value does not exist when it clearly does.
The code:
while true do wait()
local magnitude = (script.Parent.Position-workspace.Mirror.GLASS.Reflection3.Torso.Position).Magnitude
if magnitude < 3.5 then
script.Parent.BrickColor = BrickColor.new("Really red")
script.Parent.Size = Vector3.new(4,0.6,4)
workspace.Door.Pressed=true
end
end
You are telling the script to find a property named Pressed in the door (which doesn’t exist) and set it’s value to true. Add a .Value at the end like workspace.Door.Pressed.Value and it should work
What you’re doing here is you’re trying to Get Pressed before it event Exists! Either Add a check for if it’s there or Wait for it (Not Recommended on the server as this could yield forever!)
Here’s how you can do it!
while true do wait()
local Pressed = workspace.Door:FindFirstChild("Pressed")
if Pressed then
workspace.Door:WaitForChild("Pressed").Value = true
end
end
And if you want a crazy BooleanValue that changes every moment You can do this
while true do wait()
local Pressed = workspace.Door:FindFirstChild("Pressed")
if Pressed then
workspace.Door:WaitForChild("Pressed").Value = not workspace.Door:WaitForChild("Pressed").Value
end
end
While this solution is another thing you have to look out for, it is not essentially the answer. The Error indicates that the “Pressed” BooleanValue did not even exist hence it could not be changed. Whether you were changing itself or its property comes after that
I have encountered this lots of times already and adding that you need to modify a property of an object fixes the issue. Directly setting an object gives this error regardless of it’s existence, take this image for example:
(notice that the camera always exists in workspace and this is a console command)
I apologize if my answer to the reason why this happens isn’t correct, but I know for sure it’s not because the object doesn’t exist