Help with BoolValue

Hello everyone! I’m trying to use a bool value, to mute a radio if the player is playing or to turn this one if he’s in the lobby. But my script is not working (I’ve never used any values before)

Here’s the script:
local IsPlaying = script.Parent.Value
local EntraceRadio = game:GetService(“Workspace”).Radio

if IsPlaying == true then
	EntraceRadio.Music.Volume = 0
end

Here’s the path of the value and the LocalScript
game:GetService("StarterPlayer").StarterPlayerScripts.IsPlaying

Can you make screenshot of your explorer ?

if IsPlaying.Value == true then
	EntraceRadio.Music.Volume = 0
end

You just needed to get the “Value” property of the BoolValue instance itself that’s where the value is stored.

1 Like

image

Move that BoolValue into the script & make sure it’s being referenced correctly from the script & make the change I provided above (that folder is for scripts only).

Should look like this.

local IsPlaying = script:WaitForChild("IsPlaying")
1 Like

Didn’t worked, I can still hear the music…

Can I see the entire script? Also what is inside “IsPlaying” and where is the script currently located?

You should not declare IsPlaying as a variable. Variable aren’t shortcuts. They are storages. For example:

local A = 10
local B = A
A = 20

print(A, B) -- 20, 10

The script above try to store A as a variable and name it as B, as A is 10 at the moment when B is defined. Which B will be 10, but at the next line, A was changed to 20, which B will not change because B is not a shortcut, it’s a variable.

What you are doing right now is making IsPlaying variable as a “shortcut” which will only set it to true or false, depending on what script.Parent.Value is when defining IsPlaying.

What you should do instead:

local IsPlaying = script.Parent
local EntraceRadio = game.Workspace.Radio

-- Also, did you know you do not need to use :GetService() on workspace
-- Other than workspace, I recommend you to use :GetService() on them
-- I'd recommend use workspace though, as it is the shortest

if IsPlaying.Value == true then -- You do not need the == true too, but that's ok!
    EntraceRadio.Music.Volume = 0
end

If you want the radio’s music’s volume to be toggleable, you should check on when IsPlaying is changed:

local IsPlaying = script.Parent.IsPlaying
local EntraceRadio = game.Workspace.Radio

IsPlaying.Changed:Connect(function()
    if IsPlaying.Value == true then
        EntraceRadio.Music.Volume = 0
    else
        EntraceRadio.Music.Volume = 1
    end
end)

Not much explanation for the .Changed really. They are just detecting changes from the value so I don’t need to put out another paragraph so bye

1 Like

script is located in StarterPlayerScripts
here’s the entire script:

local IsPlaying = script:WaitForChild("IsPlaying")
local EntraceRadio = game:GetService("Workspace").Radio

if IsPlaying.Value == true then
EntraceRadio.Music.Volume = 0
EntraceRadio.Static.Volume = 0
end
local IsPlaying = script:WaitForChild("IsPlaying")
local Radio = workspace:WaitForChild("Radio")
local Music = Radio:WaitForChild("Music")

IsPlaying.Changed:Connect(function()
	if IsPlaying.Value then
		Music.Volume = 0
	end
end)

And how are you changing the IsPlaying BoolValue? Is that done from another script?

1 Like

Very well explained, thank you so much!

It will be done with another script, or RemoteEvent, but for now I’m testing it by manually turning it to true by locating my player in explorer while testing.

Alright, well the above script I provided should work, remember that when you change the value from a local script it won’t replicate to the server. Is the song being played from a server script or local script?

Yes, that’s the objective. Thank you for the help! It worked perfectly!