Updating BoolValue through Server, client is not recieving boolValue update?

I want to change a camera back to the player after the game has finished.

whenever I change the player’s spectating value (the value indicating that they are currently spectating) to false on the server, it does not update on the client. If this value were to update on the client, it would solve the issue.

I’ve tried adding waits to see if it was lag or the changed event being called too soon and that was not the issue. I’ve never had a problem in which the client does not replicate the changes caused by a server script.

serverScript:

for i =1, #plrs do
	plrs[i].Values.spectating.Value = false
end

localScript:

spectating.Changed:Connect(function()
	if player.Values.spectating.Value == true then
		if game.Workspace.ValueFolder.gameStarted.Value == true then
			player.PlayerGui.specafk.Spectate.enabled.Visible = true
			local children = game.Workspace.spectateCameraPlayers:GetChildren()
			local toBeSpectated = (player.Values.playerNumSpectating.Value % #children)+1


			game.Workspace.CurrentCamera.CameraSubject = game.Workspace:WaitForChild(children[toBeSpectated].Value)
			player.Values.playerSpectating.Value = children[toBeSpectated].Value
			playerName = children[toBeSpectated].Value

		end

	else
		player.PlayerGui.specafk.Spectate.enabled.Visible = false
		game.Workspace.CurrentCamera.CameraSubject = player.Character
	end
end)
1 Like

I think this should be == false

2 Likes

That’s my fault, I’ll go ahead and update my original post with the full code.

1 Like

ever tried using remote event?

Yeah I’ve used them, starting to think I should just use that here too, probably makes more sense now that I think about it, I’ll go ahead and give it a try.

2 Likes

I think it dont update table of players

for i,v in ipairs(game.Players:GetPlayers()) do
 v.Values.spectating.Value = false
end

Yea give it a try, remote events is useful when you need to make something on client and server, remote events is useful to fire something that client or server has made.

1 Like

yep just adding a remoteEvent worked, I’ll mark this as the solution, but I still am curious as to why the value wasnt being set without the remote event.

the table of players was correct. Heres a look at the code i added:

server:

plrs[i].Values.spectating.Value = false
plrs[i].PlayerGui.specafk.Spectate.TextButton.LocalScript.RemoteEvent:FireClient(plrs[i])

client:

script.RemoteEvent.OnClientEvent:Connect(function()
	player.Values.spectating.Value = false
end)

I am glad the topic has been solved! Good luck making the experience. :>

1 Like

The reason is that the player doesn’t have access to a serverscript or either server stuff. To make something like that, you either need to make a remote event or a remote function.

Think about a part, when you change a part locally, the server doesn’t receive this information, same when server gives specific data to the game. Remote events provide a structured way to synchronize information between the server and the clients. This ensures that both sides are aware of changes happening in the game world.

When you fired the client on the server it was like: “Hey client! I just send you an information, the value of spectating just got a change!”. And when the Client “saw” that, it was like: “Oh yes, the value got changed! I will make use of that now.” Without a remote event, the client-side script might be reacting to changes in real-time but without the most up-to-date information from the server. This could lead to timing issues and unexpected behavior too!

When the server has changed the BoolValue, the localPlayer was not even witnessing that, just the server.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.