Problems with changing values by remote events(client-->server)

We have the following:

If I click on the button, the button will have “Text = True”, if I do the same again, it will have “Text = False”

Code(LocalScript):

local ReplicatedStorage = game:WaitForChild(“ReplicatedStorage”)

script.Parent.Frame.TextButton.MouseButton1Click:Connect(function()
if script.Parent.Frame.TextButton.Text == “True” then
script.Parent.Frame.TextButton.Text = “False”
local f = “False”
ReplicatedStorage.RemoteEvent:FireServer(f)
elseif script.Parent.Frame.TextButton.Text == “False” then
script.Parent.Frame.TextButton.Text = “True”
local f = “True”
ReplicatedStorage.RemoteEvent:FireServer(f)
end
end)

And this value (called “f” will be taken from a local script to a serverscript (via a remote event)

Code(ServerScript1):

while wait(1) do
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, f)
if f == “False” then
game.ServerScriptService.Test.Value.Value = “False”
elseif f == “True” then
game.ServerScriptService.Test.Value.Value = “True”
end
end)
end

This is where this script will check if “f” is “True” or “False” and will make the “BoolValue” Located inside ServerScript2 have the respective value assigned

And now ServerScript2 will check if the “BoolValue” is “True” or “False” and will print the corresponding answer below.

Code(ServerScript2):

local ServerScriptService = game:GetService(“ServerScriptService”)

while wait(1) do
if ServerScriptService.Test.Value.Value == true then
print(“nice”)
elseif ServerScriptService.Test.Value.Value == false then
print(“bad”)
end
end

What’s the problem?

As seen here the system works correctly however when I click again the second time the button goes “False” it will simply continue to print “nice” instead of “bad”.

What have I done wrong?
Here is the place:test.rbxl (27.3 KB)

well you are putting a while loop around an event and you don’t need that. if you have an event it listens for it automatically so remove the while loop around the OnServerEvent.

EDIT: so this actually does not fix it yet though so lemme find the problem

1 Like

So the value is a BoolValue not a StringValue meaning that you don’t set it by doing game.ServerScriptService.Test.Value.Value = "False"
Cause the “” around False means that you are making it a string but boolvalues don’t hold strings they hold true or false so just change it to true or false without “” and also without capital letters

1 Like

You are confusing the string "True" with the boolean true.
Also remove the while loop around the events.

You can use GetPropertyChangedSignal("Value") instead of the while wait(1) do loop

2 Likes

bruh, I forgot about that, thanks sybrand725

I also appreciate the help of Apenz1

1 Like

I would also recommend what Apenz1 said to use GetPropertyChangedSignal(“Value”). It listens for if the value changes instead of using a while loop so just do in the test script

ServerScriptService.Test.Value.Value:GetPropertyChangedSignal("Value"):Connect(function()
	if ServerScriptService.Test.Value.Value  == true then
		print("nice")
	elseif ServerScriptService.Test.Value.Value == false then
		print("bad")
	end
end)

so now it only prints out when the value changes

2 Likes