Help with client/server Value setting and Read

I am trying to use the value of a BoolValue in a tool in the client in a wait loop (for testing only) where the loop is waiting for the value to change which was requested via an InvokeServer.

ClientCode is

	SetBotValue:InvokeServer(Bot,"DigEnded",true)
	while (Bot.DigEnded.Value == false) do
		wait()
		print("BotDig waiting tag change=",Bot.DigEnded.Value,".")
	end
	print("BotDig ",Bot.Name," Ended")

server code is

local function OnSetBotValue(player,Bot,ValueName,Value)
	print("SetBotValue ",player.Name,Bot.Name,ValueName,Value)
	local target = Bot:FindFirstChild(ValueName)
	if target then
		target.Value = Value
	else
		print("SetBotValue target ",ValueName," notfound")
	end
end

Problem is server view shows it true

and client view shows its false


and also the loop is stuck as seen in the client output

I have been believing that value set on the server would be the same for server and client.
Would someone please help me to understand this.

May I sugges-

Ok, I think the problem is here:

if target then
    target.Value = Value

I think why the server is always printing false is because you didn’t put a print command after the line(target.Value = Value), which I would predict would also print true.

the print command(print("BotDig waiting tag change=",Bot.DigEnded.Value,".")) in the client code would always print false because once DigEnded is true it wouldn’t print anymore.

Correct me if I’m wrong.

on the server t.The if target.e is confirming that the request value item has been found from the FindFirstChild statement.
on the client the print does not stop as the loop never exits.
this is indicated by the (hard to see) print showing 3724 repeats.
the screen shots show the property whilst the loop is running.
What I don’t get is why they are different since the server has set the value to true as required by the InvokeServer and seen in the server screen shot.

Will you be able to try this out?:

while true do
	wait()
	print("BotDig waiting tag change=",Bot.DigEnded.Value,".")
    if Bot.DigEnded.Value == true then
        break
    end
end

same problem. the print just keep printing. The properties values on client and server are different.

I have to go off now. Be back on tomorrow. Sorry.

I’m going to try to reproduce this, and I’ll edit this post once I’m done

Edit: Having the same issue

Edit2: I don’t have the problem anymore

So I used a player added event on the server:

game.Players.PlayerAdded:Connect(function(player)

    wait(16)

    player.PlayerGui.Hypo.DigEnded.Value = true

    print(player.PlayerGui.Hypo.DigEnded.Value)

end)

and A detecting script in the client

local Bot = script.Parent.Bot

while Bot.DigEnded.Value == false do

wait()

print("BotDig waiting tag change=",Bot.DigEnded.Value,".")

end

print("BotDig ",Bot.Name," Ended")

Output:

BotDig waiting tag change= false . (x160)

BotDig waiting tag change= false .

BotDig waiting tag change= true .

BotDig Hypo Ended

That does add some light onto the fact that this works ok the first time but not subsequently.
It implies that I have somehow lost the connection to some part of the game.
I added
print(“Bot FullName”,Bot:GetFullName())
to both client and server
and got
Bot FullName Workspace.Player1.Controller.Handle.BotMaster
from both client and server.
Still failing on second dig so will have to check all things each time to see if I can see a difference.
This may take some time.
Thanks for your help so far.

Ok. Found it. Before calling the digging routine I set the DigEnded value to false.
The problem was I was doing it on the client in two locations I had missed.
The first time worked because the server value was already false.
Any subsequent time the server value would not be changed so the code just went wrong.
Fixed by searching again for all instances where the DigEnded.Value in the client was being set and replacing that with the ServerInvoke.
I will mark your response as the solution as it was that which gave me the change to my research thinking which concluded with this fix.

3 Likes