Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is it not working when I make a script to turn the bool value on?

Asked by
bt6k 23
4 years ago

It is a very simples script, I don't know if I am missing some rules..

local dark = game.Workspace.Dark.Value
local light = script.Parent:FindFirstChild("Sector 1 Light")

if dark == true then
    light.BrickColor = BrickColor.new("Really black")

end

the game.Workspace.Dark is a bool value that I have in the workspace. I made a script inside it telling it to immediately go to true, but the script right here that you are seeing is in a light. This light is not changing brickcolors.

0
Light doesn’t take a brick color. Try changing the time . eyad27 8 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Hello.


The problem with your script is that the if statement would only run once and end the script.

To fix this, you must connect the dark value to a Changed event. It will fire whenever its value is changed.


Also, I removed the .Value in the dark variable as the variable stores a boolean from the start of the game.


Anyways, here's your fixed script:

local dark = game.Workspace.Dark
local light = script.Parent:FindFirstChild("Sector 1 Light")

dark.Changed:Connect(function()
    if dark.Value == true then
        light.BrickColor = BrickColor.new("Really black")
    end
end)

I hope this helps, cheers!

Ad

Answer this question