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

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

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.

1 comment

0

Hey on line 5 you put .Value 2 times remove 1

1 answer

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.

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