Bool Value can't change from Server to Client

Hi There, been having issues with changing Bool Values from Server to Client, I already tried to make a Event.

Here’s the deal: Whenever a LocalPlayer chooses a Character from the GUI, it will fire a Event from Client to Server.

After it, another Remote Event is fired from Server to Client indicating that they can now access all GUIs.

First Client Side Code

CharacterFrame.Choose.MouseButton1Click:Connect(function()
		if CharacterFrame.Choose.X.Text == "Selected" then
			return 
		end
		local AdditionalButton = script.Parent.Parent.AdditionalButtons
		game.ReplicatedStorage.DiamondsEvent:FireServer(character.Name)
		script.Parent.Visible = false
		AdditionalButton.Visible = false
		for i, characterfr in pairs(script.Parent.Characters:GetChildren()) do
			if characterfr:IsA("ViewportFrame") then
				characterfr.Choose.X.Text = "Select"
			end
		end
		CharacterFrame.Choose.X.Text = "Selected"
	end)

Server Side Code

game.ReplicatedStorage:WaitForChild("DiamondsEvent").OnServerEvent:Connect(function(player, chosenCharacter)
	RSG.CharacterClientEvent:FireClient(player, false)
... -- This is all that it needs from the Server Side to be seen, the rest are Detecting to Morph to a Character

It works up until this part, but when its firing back to a different script, it doesn’t work. Though it doesn’t give back any Errors.

Client side Code

function DetectMorphValue(toggle)
	if toggle == false then
		SCBool.Value = false
	else
		SCBool.Value = true
	end
end

CharacterClientEvent.OnClientEvent:Connect(DetectMorphValue)

This is how my Explorer in StarterGui and ServerScriptService Looks like
image

I believe you’re checking if “player” == true, not the value you sent across. Change detectmorphvalue to detectmorphvalue(player, toggle).

That didn’t work too, I tried to change DetectMorphValue to DetectMorphValue(player, toggle) but since its a client event, shouldn’t it need to call player since its local?

image

no error on my end, but the Bool Value is still set to true even if I have morphed already.

I just replicated what you’re doing and it worked perfectly fine. Are you sure the function is running? Is there any possibility you’re firing back with an event the client cannot see?

hold on, so there’s nothing suppose to be wrong with it? :sob: well whenever I morph into a character, I respawn but stay on the same area where I’m standing.

pls don’t tell me that it worked but whenever I respawn it resets back to true- because if it does, this post would be just so dumb :sob:

Is there any possibility you’re firing back with an event the client cannot see?

Nope, I’m pretty sure I’m using FireClient to send back to the Client’s side

That’s… probably the issue. If your value is ‘true’ by default and is placed in a place where it will be reset every time your character does… yeah. You can consider having a value on the server for each player joined instead.

is there anyway I can just do a while loop on the startergui? it seems more complicated that way for me :sob: but I’ll try and see if its a better solution to what I’m making

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

Players.PlayerAdded:Connect(function(Player)
	
	task.wait()
	
	local Value = Instance.new("BoolValue")
	Value.Name = Player.Name.."'s value"
	Value.Value = true
	Value.Parent = ReplicatedStorage
	
end)

Something like this in ServerScriptService should do… you can reference it in your script by doing

ReplicatedStorage[player.Name.."'s value"].Value

Remember to delete the value once the player leaves with :Destroy()

ooo so your telling me, that I should just make a value for every player in the server, and have it changed server side if the player changed to another character.

and possibly have my local script in local player side to listen to that so whenever it checks if the value is changed, it can enable what I want to do?

game.ReplicatedStorage:WaitForChild("DiamondsEvent").OnServerEvent:Connect(function(player, chosenCharacter)
	RSG:WaitForChild("PlayerValue")[player.Name.."'s value"].Value = false
...

so this only sets the Value of the Current Player to false in ReplicatedStorage.

now im trying to detect the changes to the bool value from localscript

THANK YOUUU it actually works, I can continue working on this now. Thank you sm!!

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