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

?True/False value won't change

I have a script to change values, which works on one car but not on the other. The script is meant to make a lightbar light up. The lights, who are located inside another model within the car, have their own script which works.

UPDATE I believe this is the problem:

local isOn = false

veh = game.Workspace:FindFirstChild(script.Parent.Parent.CarName.Value, true)

function on() 
	isOn = true
    veh.lightbar1.on.Value = false
        
end

function off() 
	isOn = false
    veh.lightbar1.on.Value = true
end

function onButtonClicked()
	
	if isOn == true then off() else on() end

end

script.Parent.MouseButton1Click:connect(onButtonClicked)

on()

1 comment

0

for future reference "true/false values" are usually referred to as "bool values"

2 answers

local isOn = false

veh = script.Parent.Parent.CarName.Value

function on() 
    isOn = true
    veh.Value = false

end

function off() 
    isOn = false
    veh.Value = true
end

function onButtonClicked()

    if isOn == true then 
         off() 
    else 
         on() 
    end

end

script.Parent.MouseButton1Click:Connect(onButtonClicked)

@DinozCreates

2 comments

0

I editted my answer.

0

Still not working. Would you be able to fix it if I were to add you into team create?

This should work like a toggle switch as long as the Variable is correct and you've got it placed in the correct location.

veh = script.Parent.Parent.CarName.Value

function onButtonClicked()
	veh.Value = not veh.Value
end

script.Parent.MouseButton1Click:Connect(onButtonClicked)

4 comments

0

compact it even more. Remove the entire if statement and change it into ----- veh.Value = not veh.Value

0

Neg rep, really?

0

That doesn't work for me, I updated the question because I feel like that may be the problem. Thanks for trying though.

0

Can you show me what you ended up with after adding in the correct variable to my script? I think you may be referencing the bool incorrectly

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