Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't my boolvalue change?

Okay, I'll get straight to the point. I want my script to change the boolvalue to true once the button is pressed and I don't really know how to do that, I'm sort-of new to scripting.

local screen = script.Parent.Parent.Screen
local light = script.Parent.Parent.Light.SurfaceLight
local IsOn = script.Parent.IsOn.Value
IsOn = true

script.Parent.ClickDetector.MouseClick:Connect(function()
	if IsOn then
		IsOn=false
		light.Enabled = false
		screen.BrickColor = BrickColor.Black()
		screen.Material = Enum.Material.SmoothPlastic
	elseif not IsOn then
		IsOn=true
		light.Enabled = true
		screen.BrickColor = BrickColor.Blue()
		screen.Material = Enum.Material.Neon
	end
end)

1 answer

✓ Accepted answer

The issue here is that you are defining IsOn twice at the start of the script. The second declaration of the variable is what the variable becomes since scripts run top to bottom. Get rid of line 4 and edit the actual IsOn BoolValue object to be true at first.

local screen = script.Parent.Parent.Screen
local light = script.Parent.Parent.Light.SurfaceLight
local IsOn = script.Parent.IsOn.Value

script.Parent.ClickDetector.MouseClick:Connect(function()
    if IsOn then
        IsOn=false
        light.Enabled = false
        screen.BrickColor = BrickColor.Black()
        screen.Material = Enum.Material.SmoothPlastic
    elseif not IsOn then
        IsOn=true
        light.Enabled = true
        screen.BrickColor = BrickColor.Blue()
        screen.Material = Enum.Material.Neon
    end
end)

1 comment

0

Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.