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

Bool values not changing ?

Theres 2 of bool's Muted, Unmuted when i click they don't change do i require something more or no ?

local music = script.Parent.music
local a = script.Parent
local Unmuted = script.Parent.Unmuted.Value
local Muted = script.Parent.Muted.Value

a.MouseButton1Click:connect(function()
	if music.Volume == 1 then
	if Muted == false then
		Muted = true
		Unmuted = false
		a.ImageColor3 = Color3.new(255/255, 89/255, 92/255) --muted
	end
else 
	if Unmuted == false then
		Unmuted = true
		Muted = false
		a.ImageColor3 = Color3.new(99/255, 225/255, 109/255) --unmuted
		end
	end
end)

1 answer

✓ Accepted answer

Hello!

Thanks for reporting this issue here, on Scripting Helpers.

This issue has to do with something called Binary Scope. Once you set the local before the variable, it will make it only available to all Scopes inside that single Scope.

For example... If you have ...

local i=1 function t() print(i) end 

It will return 1. However, if you use...

local i=1 function t() local i=2 print(i) end print(i)

It would return: 2 1 But if you hadn't use local inside the function, it would change i to 2, returning 2 2

This means that when you use local Unmuted = ... everytime you change Unmuted it won't change the object.

Also, why are you using

if music.Volume == 1

? That way muting won't work.

This is the correct code:

wait(0)
local music = script.Parent:WaitForChild('music')
local a = script.Parent
local Unmuted = script.Parent.Unmuted.Value
local Muted = script.Parent.Muted.Value

a.MouseButton1Click:connect(function()
    if Muted == false then
        script.Parent.Muted.Value = true
        script.Parent.Unmuted.Value = false
        a.ImageColor3 = Color3.new(255/255, 89/255, 92/255) --muted
    elseif Unmuted == false then
        script.Parent.Unmuted.Value = true
        script.Parent.Muted.Value = false
        a.ImageColor3 = Color3.new(99/255, 225/255, 109/255) --unmuted
     end
Muted=script.Parent.Muted.Value
Unmuted=script.Parent.Unmuted.Value
end)

3 comments

1

It doesn't work my button gets stuck

0

Could you please tell me the output?

0

Thank you for contacting Scripting Helpers, Home of helpful programmers like you. How may we help you today sir?

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