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

Why doesn't this work? (Activating a bool value with a script)

Asked by 3 years ago
local RS = game:GetService("ReplicatedStorage")
local alert = RS:WaitForChild("alert1")
local turnoff = RS:WaitForChild("turnoff1")

local ison = game.Workspace.Post1.buttons.ALERT.Value.Value
local sound = game.Workspace.Speaker.speaker.sound

alert.OnServerEvent:Connect(function()
    sound.Playing = true
    ison = true
end)
if ison == true then
    print("ison = true")
end
turnoff.OnServerEvent:Connect(function()
    sound.Playing = false
    ison = false
end)

What this is for is an alarm system. The "ison" value is boolean and is to check if the sound is on or not. In the Local Script, it detects if the ison value is true, and fires the correct event accordingly. Why doesn't it turn on though? The sound works, it plays fine, but the ison value never becomes true.

0
Hey on line 5 you put .Value 2 times remove 1 FirezDevv 162 — 3y

1 answer

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

Try this:

local RS = game:GetService("ReplicatedStorage")
local alert = RS:WaitForChild("alert1")
local turnoff = RS:WaitForChild("turnoff1")

local ison = game.Workspace.Post1.buttons.ALERT -- I'm not sure why you had 2 calls to the .Value property.
local sound = game.Workspace.Speaker.speaker.sound

alert.OnServerEvent:Connect(function()
    sound.Playing = true
    ison.Value = true
end)
if ison.Value == true then
    print("ison = true")
end
turnoff.OnServerEvent:Connect(function()
    sound.Playing = false
    ison.Value = false
end)

Assuming that the object 'ison' is getting the value of is named 'ALERT', this should work.

Ad

Answer this question