UI image not changing as intended

i hate this so much iv spent 2 hours on this and i need help
why wont the image change when i do this?

local b = script.Parent

local ssa = true


b.MouseButton1Down:Connect(function()
	
	b.Position = UDim2.new(0.063, 0,0.36, 0)
end)

b.MouseButton1Up:Connect(function()
	
	b.Position = UDim2.new(0.063, 0,0.352, 0)
	script.Parent.Sound:Play()
	if ssa == true then
		script.Parent.Image = "rbxassetid://6883581637"
		script.Parent.Parent.MuteMusic.Image = "rbxassetid://6883581637"
		local ssa = false	
	else
		script.Parent.Image = "rbxassetid://6883523025"
		script.Parent.Parent.MuteMusic.Image = "rbxassetid://6883523025"
		local ssa = true
end

	
	
end)

b.MouseEnter:Connect(function()
	b.ImageColor3 = Color3.new(1,1,1)
end)

b.MouseLeave:Connect(function()
	b.Position = UDim2.new(0.063, 0,0.352, 0)
	b.ImageColor3 = Color3.new(0.862745, 0.862745, 0.862745)
end)

Does it show any errors? Maybe that could help us.

1 Like

Is it local? What’s the output? Maybe try putting in print commands with the current id and it after it “changes”.

I don’t know if this helps but, you’re missing an end

1 Like

where?

please put a updated script

local b = script.Parent

local ssa = true


b.MouseButton1Down:Connect(function()
	
	b.Position = UDim2.new(0.063, 0,0.36, 0)
end)

b.MouseButton1Up:Connect(function()
	
	b.Position = UDim2.new(0.063, 0,0.352, 0)
	script.Parent.Sound:Play()
	if ssa == true then
		script.Parent.Image = "rbxassetid://6883581637"
		script.Parent.Parent.MuteMusic.Image = "rbxassetid://6883581637"
		local ssa = false	
	else
		script.Parent.Image = "rbxassetid://6883523025"
		script.Parent.Parent.MuteMusic.Image = "rbxassetid://6883523025"
		local ssa = true
end
end

	
	
end)

b.MouseEnter:Connect(function()
	b.ImageColor3 = Color3.new(1,1,1)
end)

b.MouseLeave:Connect(function()
	b.Position = UDim2.new(0.063, 0,0.352, 0)
	b.ImageColor3 = Color3.new(0.862745, 0.862745, 0.862745)
end)

you missed an end at the if statment thats in the mousebutton1up

I’m not sure what you mean? He does have the appropriate end’s in his script. With your script it will error, as he already has the 2 needed.

yeah thats what i thought. can you please help

The issue is in this block:

b.MouseButton1Up:Connect(function()

	b.Position = UDim2.new(0.063, 0,0.352, 0)
	--script.Parent.Sound:Play()
	if ssa == true then
		script.Parent.Image = "rbxassetid://6883581637"
		script.Parent.Parent.MuteMusic.Image = "rbxassetid://6883581637"
		local ssa = false	--Issue here.
	else
		script.Parent.Image = "rbxassetid://6883523025"
		script.Parent.Parent.MuteMusic.Image = "rbxassetid://6883523025"
		local ssa = true	--Issue here.
	end
end)

The assignment of ssa in these scopes is defining a new variable that is shadowing the wider-scope ssa. This is not what you want. Remove the local from in front of each and it will work (like this):

b.MouseButton1Up:Connect(function()

	b.Position = UDim2.new(0.063, 0,0.352, 0)
	--script.Parent.Sound:Play()
	if ssa == true then
		script.Parent.Image = "rbxassetid://6883581637"
		script.Parent.Parent.MuteMusic.Image = "rbxassetid://6883581637"
		ssa = false
	else
		script.Parent.Image = "rbxassetid://6883523025"
		script.Parent.Parent.MuteMusic.Image = "rbxassetid://6883523025"
		ssa = true
	end
end)
2 Likes

It worked! Thanks for the help.

1 Like