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

?True/False value won't change

Asked by 5 years ago
Edited 5 years ago

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()

0
for future reference "true/false values" are usually referred to as "bool values" User#22604 1 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
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

0
I editted my answer. DinozCreates 1070 — 5y
0
Still not working. Would you be able to fix it if I were to add you into team create? ConstableArkwright 0 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

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)
0
compact it even more. Remove the entire if statement and change it into ----- veh.Value = not veh.Value RubenKan 3615 — 5y
0
Neg rep, really? DinozCreates 1070 — 5y
0
That doesn't work for me, I updated the question because I feel like that may be the problem. Thanks for trying though. ConstableArkwright 0 — 5y
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 DinozCreates 1070 — 5y

Answer this question