✓ 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)
elseif Unmuted == false then
script.Parent.Unmuted.Value = true
script.Parent.Muted.Value = false
a.ImageColor3 = Color3.new(99/255, 225/255, 109/255)
end
Muted=script.Parent.Muted.Value
Unmuted=script.Parent.Unmuted.Value
end)
3 comments
It doesn't work my button gets stuck
Could you please tell me the output?
Thank you for contacting Scripting Helpers, Home of helpful programmers like you. How may we help you today sir?