Just as the title says. I have no idea why this happens since this is the first time that this has ever happened to me. Value is added through remote events so datasave can save the data.
LocalScript inside replicatedfirst (musicon value is on 1 but it still plays the sound):
local player = game.Players.LocalPlayer
local MusicNumber = player:WaitForChild("Stats"):WaitForChild("MusicNumber")
local MusicON = player.Stats:WaitForChild("MusicON")
local Waiter = player:WaitForChild("Stats").Waiter
local RS = game:GetService("ReplicatedStorage")
local WaiterAdder = RS.Settings:WaitForChild("WaiterAdder")
local MusicNumberAdder = RS.Settings:WaitForChild("MusicNumberAdder")
local SoundService = game:GetService("SoundService")
local Adventure1 = SoundService.Adventure1
local Buddy2 = SoundService.Buddy2
local Poolside3 = SoundService.Poolside3
local Skyline4 = SoundService.Skyline4
local Journey5 = SoundService.Journey5
local ONButton = player.PlayerGui.SystemGUI2.MainFrame.Menu.SettingsFrame.Music.ON
local OFFButton = player.PlayerGui.SystemGUI2.MainFrame.Menu.SettingsFrame.Music.OFF
if MusicON.Value == 20 then
Adventure1:Play()
ONButton.BackgroundColor3 = Color3.fromRGB(63, 255, 33)
OFFButton.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
Adventure1.Ended:Wait()
WaiterAdder:FireServer()
wait(0.5)
end
Check if the MusicON value is being updated correctly through the remote event, make sure the variable is of the correct type, verify the path to the variable, add debug statements, and consider using the ValueChanged event for accurate response to updates.
The check is probably happening before the value is changed. That’s my guess. I don’t know how you would fix it because I don’t know what your code on the server looks like. Posting that would be very helpful
Regarding your first bit I just put the number 20 there as a test to see if the script would still run. The value never hits 20 but the script detects so.
This is where i add the value:
local RS = game:GetService("ReplicatedStorage")
local MusicONAdder = RS.Settings:WaitForChild("MusicONAdder")
MusicONAdder.OnServerEvent:Connect(function(player)
local MusicNumber = player.Stats:WaitForChild("MusicNumber")
local MusicON = player.Stats:WaitForChild("MusicON")
if MusicNumber.Value == 0 then
MusicON.Value = 1
elseif MusicNumber.Value == 1 then
MusicON.Value = 2
elseif MusicNumber.Value == 2 then
MusicON.Value = 3
elseif MusicNumber.Value == 3 then
MusicON.Value = 4
elseif MusicNumber.Value == 4 then
MusicON.Value = 5
end
end)
Pretty sure everything is correct, and the ValueChanged event wouldn’t work in this case because the script only runs once whenever the player joins before any value is set.
you can use the ValueChanged event to detect changes to the MusicON value. by listening to this event, the LocalScript will be able to react and update the sound playing based on the updated value, resolving any timing mismatch between the value update and the script execution.
Yeah sorry if I wasn’t understandable. So all in all this script is a rejoin checker to see if the player put the music to on or off in the settings. This is the ON part of it. The problem is I can put anything I want in the if statement like player.Character.Humanoid.MaxHealth == 1 the script would STILL run. This has nothing to do with the MusicON value. Something else is the case.
Like I said, I just put the number 20 there as a test to see if the script would still run. The problem is I can put anything I want in the if statement like player.Character.Humanoid.MaxHealth == 1 the script would STILL run. This has nothing to do with the MusicON value. Something else is the case.
Yeah ty for that. Because of that I realised what is the problem. When I duplicated the script from startergui to replicatedfirst to test if that would work I didn’t disable the script in the startergui. So both of them ran. The script in the replicatedfirst now works. Well sorry for taking your time with my silly little mistake. <3