Attempt to index nil with 'value'

Greetings,

I wanted to change the value of a BoolValue that I use to turn music on or off. The value doesn’t change and instead, I got this error. The code and the error are attached down below! Thanks.

The error:

Screenshot 2022-04-19 171648

The code:

	RSMUMVOff.OnServerEvent:Connect(function(plr,musicstat)
		musicstat.Value = false
	end)

The code that sends the musicstat value:

RSMCMOff:FireServer(plr,musicstat)

Can you send the entire client code? There is something wrong with that.

Edit:
FireServer doesn’t need the player argument

RSMCMOff:FireServer(musicstat)
1 Like

Hey, here is the local script. It does not include your latest edit (the edit in your reply).

local debounce = false
local RS = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local RSMUM = RS:WaitForChild("Music"):WaitForChild("UpdateMusic")
local RSMCMOn = RS:WaitForChild("Music"):WaitForChild("ChangeMusicOn")
local RSMCMOff = RS:WaitForChild("Music"):WaitForChild("ChangeMusicOff")
local musicstat = player:WaitForChild("Music"):WaitForChild("Music")
local start = RS:WaitForChild("Start")
local button = script.Parent

button.MouseButton1Click:Connect(function(plr)
	if debounce == false then
		debounce = true 
		if musicstat.Value == true then
			RSMCMOff:FireServer(plr,musicstat)
			button.Text = "Music: Off"
			button.BackgroundColor3 = Color3.new(1, 0, 0)
		elseif musicstat.Value == false then
			RSMCMOn:FireServer(plr,musicstat)
			button.Text = "Music: On"
			button.BackgroundColor3 = Color3.new(0, 1, 0)
		end
        task.wait(0.25)
		debounce = false
	end
end)

When you use :FireServer you don’t need to specify plr. You can send the arguments directly and the server will automatically receive the player.

1 Like

Alright, I removed that plr and I received this error:

Screenshot 2022-04-19 181428

The code for Line 27 of MusicData is this:

	RSMUMVOff.OnServerEvent:Connect(function(plr,musicstat)
		musicstat.Value = false
	end)

Musicstat is equal to nil because you sending client stuff to the server that the result of Musicstat will become nil

Note that anything that sends from client to server like instance will be nil since it won’t replicate it. But UTF-8 characters won’t be nill since its not an instance

Also the mouse button1Click event doesn’t return player. It’s just a blank.

May i ask you, where is the MusicStat placed?

I guess so… I am going to try to access it directly from the server script using a PlayerAdded function. I thought it might have been better to just send it through a remote event so any localization error can be gone.

Yea I always forget that MouseButton1Click does not give the player.

In LocalPlayer.Music.Music (Note that Music is a BoolValue)

RSMUMVOff.OnServerEvent:Connect(function(plr)
		plr.Music.Music.Value = false
	end)

try out this code

1 Like

Yea it works just fine, that’s what I thought about after you told me that I can’t use my initial idea. I just wanted to avoid any path-finding errors. Thanks.