Function isn't checking for the number of a NumberValue

I was working on a function where when a player joins, it checks to see if the value of a number value is equal to a certain number. And if it is, it will do a function. But for some reason it doesn’t even check anything. Here’s the code:

game.Players.PlayerAdded:Connect(function(player)
	player:WaitForChild("Settings").MusicToggle.Changed:Connect(function()
		if player.Settings.MusicToggle.Value == 0 then
			workspace:WaitForChild("Relax").Volume = 0
			player:WaitForChild("PlayerGui").Settings.Setting.Music.On:TweenPosition(UDim2.new(0.45, 0,0, 0), nil, nil, 0.3)
			player:WaitForChild("PlayerGui").Settings.Setting.Music.On.Visible = false
			player:WaitForChild("PlayerGui").Settings.Setting.Music.Off.Visible = true
			player:WaitForChild("PlayerGui").Settings.Setting.Music.Off:TweenPosition(UDim2.new(0.45, 0,0, 0), nil, nil, 0.3)
		end
	end)
end)
end)

How do you change the MusicToggle number value, do you do it manually or do you do it from a script?

The MusicToggle gets added up on the server side. And I attached a data store to the numbervalue and the default value for it is 0.

So the value stays at 0 right? Well if the default is 0 then when this script sees the number value it sees that the value is 0. Now the function won’t start until the value changes, and the value is staying at 0 so it never runs. Try changing the value to 1 in another script then changing it back to 0.

1 Like