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

How do you change a BooleanValue via script?

Asked by 4 years ago

Basically I'm trying to get the booleanvalue to change, but it doesn't change at all. I'm pretty confused, so how would you change a booleanvalue via script?

local boolvalue = script.Parent.bool
local light = game:GetService("Lighting")
local alarm = script.Parent.Parent.alarm
local message = script.Parent.Parent.corevent
local temp = script.Parent.SurfaceGui.Text

while true do
    wait()
        if temp.Text == "1999°c" then
        boolvalue = true
        alarm.Looped = false
    elseif temp.Text == "2000°c" then
        script.Parent.Parent.Map.coremachine.coreOverheat.Fire.Enabled = true
        alarm.Looped = true
        boolvalue.Value = false

repeat


            message:Play()
            light.Ambient = Color3.new(150/255,0/255,0/255)
            alarm:Play()
            wait(0.2)
            light.Ambient = Color3.new(0/255,0/255,0/255)
            wait(0.9)
            light.Ambient = Color3.new(150/255,0/255,0/255)
until boolvalue.Value == true
        end
        end

3 answers

Log in to vote
0
Answered by 4 years ago

Revising my answer a third time because I made a mistake of putting stuff after the while true do loop lol

Try this and see if it works

local boolvalue = script.Parent.bool
local light = game:GetService("Lighting")
local alarm = script.Parent.Parent.alarm
local message = script.Parent.Parent.corevent
local temp = script.Parent.SurfaceGui.Text

local function change(v)
    if (v == false) then
        repeat
            message:Play()
            light.Ambient = Color3.new(150/255,0/255,0/255)
            alarm:Play()
            wait(0.2)
            light.Ambient = Color3.new(0/255,0/255,0/255)
            wait(0.9)
            light.Ambient = Color3.new(150/255,0/255,0/255)
        until boolvalue.Value == true
    end
end

boolvalue.Changed:Connect(change)
change(boolvalue.Value)

while true do
    wait()
        if temp.Text == "1999°c" then
        boolvalue.Value = true
        alarm.Looped = false
    elseif temp.Text == "2000°c" then
        script.Parent.Parent.Map.coremachine.coreOverheat.Fire.Enabled = true
        alarm.Looped = true
        boolvalue.Value = false
    end
end
0
Oh it finally works! Omg thank you, also I was wondering where you learnt scripting? It's my third day scripting, I only have a head-start because I already know Java. FearlessX96 74 — 4y
0
I learned it over time from many different places. The biggest place of learning I can think of is developer.roblox.com with all their documentation. Now that it's fixed, remember to mark the question as solved. CeramicTile 847 — 4y
0
Yes I will after.. Also how do you navigate around in developer.roblox.com? Since it's uh, all bungled up? FearlessX96 74 — 4y
0
If you go to "Learn Roblox" button at the top of the website, it will take you to some tutorials. You can scroll around in there to probably learn something new. Otherwise easier sources would be youtube or free models, but those are kinda hit and miss. CeramicTile 847 — 4y
Ad
Log in to vote
1
Answered by
VitroxVox 884 Moderation Voter
4 years ago

Hey bro, the it works what you did. You did it right and everything but this single line breaks the whole script it's the line 10

FIXED:

local boolvalue = script.Parent.bool
local light = game:GetService("Lighting")
local alarm = script.Parent.Parent.alarm
local message = script.Parent.Parent.corevent
local temp = script.Parent.SurfaceGui.Text

while true do
    wait()
        if temp.Text == "1999°c" then
        boolvalue.Value = true
        alarm.Looped = false
    elseif temp.Text == "2000°c" then
        script.Parent.Parent.Map.coremachine.coreOverheat.Fire.Enabled = true
        alarm.Looped = true
        boolvalue.Value = false

repeat


            message:Play()
            light.Ambient = Color3.new(150/255,0/255,0/255)
            alarm:Play()
            wait(0.2)
            light.Ambient = Color3.new(0/255,0/255,0/255)
            wait(0.9)
            light.Ambient = Color3.new(150/255,0/255,0/255)
until boolvalue.Value == true
        end
        end

You had it change the value "boolvalue" and it's an object so you can't change it's value, you forgot to add ".Value" to it.

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

There is a property in every value named "Value". In order to access this property, you must reference it (The Value Property) when talking about the name of the value. Line 10 is where you made the mistake!

For Example:

local bool = game.Workspace:FindFirstChild('BoolValue')

if 1+1 == 2 then
    bool.Value = true
    wait(2)
    bool.Value = false
end)
0
The double equal sign is only used whenever your comparing two values and not when declaring. ScuffedAI 435 — 4y
0
Sorry I didn't mean to add that. JayShepherdMD 147 — 4y

Answer this question