GUI Cannot Read A Server-Side NumberValue After It Updates, Only Original Value Is Returned

Im working on a Tool that players will use to build blocks, and it comes with a resource bar to show the player how much resources they have to build with. The amount of resources remaining is stored within the Tool object itself as a NumberValue, alongside a max value.

However when I attempt to read the value, it just returns whatever the value was upon starting the playtest. Basically if the resource value was set to 200, it will always return 200 even if it changes.

I know you cant change values client-side, but im only attempting to read the value which I had no trouble with in the past with other projects. This problem persists no matter if I use .Changed or GetPropertyChangedValue(), In fact when I put a Warn() to test the code, nothing shows up, implying to me that the change isn’t even being registered period.

In the past I used loops which are way less efficient, but even that didn’t solve this problem. The code just continues to return the original value. I can confirm that the change is registered in the explorer on both the server and client.

Next I tried reading the value on the server and sending over the data using a RemoteEvent, although the .Changed/GetPropertyChangedValue() event does fire on the server and return the correct value, it does not appear to be able to send that data. The client does not seem to detect the RemoteEvent which has me completely baffled. I confirmed using Warn() that the client being sent too, and the attached data were absolutely correct.

Ive attached code samples from my various attempts to help aid in diagnosis if possible.

local TOOL = script.LINK_TO_TOOL.Value -- ObjectValue: Tool Clones A GUI When Equipped And References Itself Here Before Depositing GUI Into PlayerGui.

-- Attempt #1
TOOL.TOOLBOX_DATA.RESOURCES.Changed:Connect(function() -- Updates GUI Resource Bar When NumberValue Inside The Tool Is Changed.
	TOP_PANEL.RESOURCE_BAR.TITLE.Text = TOOL.TOOLBOX_DATA.RESOURCES.Value.." / "..TOOL.TOOLBOX_DATA.RESOURCES.MAX_RESOURCES.Value
end)

-- Attempt #2
TOOL.TOOLBOX_DATA.RESOURCES:GetPropertyChangedSignal("Value"):Connect(function() -- Updates Resource Bar When Change Is Detected.
	TOP_PANEL.RESOURCE_BAR.TITLE.Text = TOOL.TOOLBOX_DATA.RESOURCES.Value.." / "..TOOL.TOOLBOX_DATA.RESOURCES.MAX_RESOURCES.Value
end)

-- Attempt #3
while wait(0.1) do -- Updates Resource Bar When Change Is Detected.
	TOP_PANEL.RESOURCE_BAR.TITLE.Text = TOOL.TOOLBOX_DATA.RESOURCES.Value.." / "..TOOL.TOOLBOX_DATA.RESOURCES.MAX_RESOURCES.Value
end

Simply trying to read the value when it changes on the server. None of these attempts worked, the first two events don’t even seem to run. The original value is returned by the loop, and by the code elsewhere. I even tried replacing “TOOL” with “script.LINK_TO_TOOL.Value” thinking that maybe its checking the tool’s data from when the variable was first created, but that fails too. The value is not stored anywhere as a variable.

-- Server Side.
script.Parent.TOOLBOX_DATA.RESOURCES.Changed:Connect(function()
	script.Parent.REMOTE_EVENT:FireClient(PlAYER_SERVICE:GetPlayerFromCharacter(script.Parent.Parent), "UPDATE_RESOURCE_BAR", script.Parent.TOOLBOX_DATA.RESOURCES.Value)
end)

-- Client Side.
local TOOL = script.LINK_TO_TOOL.Value -- ObjectValue: Tool Clones A GUI When Equipped And References Itself Here Before Depositing GUI Into PlayerGui.

TOOL.REMOTE_EVENT.OnClientEvent:Connect(function(COMMAND, DATA)
	if COMMAND == "UPDATE_RESOURCE_BAR" then
		TOP_PANEL.RESOURCE_BAR.TITLE.Text = DATA.." / "..TOOL.TOOLBOX_DATA.RESOURCES.MAX_RESOURCES.Value
	end
end)

This was my attempt to read the data server-side and send it over. Although the updated variable is correct when read on the server, The client-side event isn’t even ran at all. I confirmed with Warn() that “PlAYER_SERVICE:GetPlayerFromCharacter(script.Parent.Parent)” is indeed returning my username so I have no idea why its failing to even go through.

Any help would be greatly appreciated!

hey, sorry but could you perhaps make you problem a bit more clear and concise? im not exactly sure what you are trying to achieve, i understood something along the lines that the numberValue is not updating? thanks

Sorry for the late reply, but basically there is a resource bar (Specifically a TextLabel) on a GUI that is linked to a tool. For example it will say “200 / 200” to show that the player has 200 resources to work with out of a maximum possible of 200.

The GUI is supposed to track the remaining resources (Which is a NumberValue stored within the tool itself) and update the TextLabel accordingly. So for example if the player spends 5 resources, it will now say “195 / 200”

The problem is that the GUI seems to be completely incapable of reading the value (beyond what it originally was upon startup, in this case 200) which ive never had any issues with before. Even reading the value server-side and sending it over with a RemoteEvent seems to fail as it wont even detect the incoming signal. Ive scowered the DevHub and DevForum and cant find any reason for this behavior, as far as I know it should be completely possible to read a NumberValue on the server from the client.

So this number value is in the players gui and you are updating it with a server script or client script? If it is in the gui, you should be updating it with a local script because it is local to that specific player. As for the remote event, the number value does not exist on the server, therefore it will return nil when passed through a remote event. I think it should work if you pass the value of the number value directly instead

1 Like

Hi @General_Ace90,

I think the problem with your script is not related to Changed or GetPropertyChangedSignal. The issue is that the ObjectValue’s value is still set to the original tool, not the new one.

So TOOLBOX_DATA.RESOURCES.MAX_RESOURCES.Value is only reading from original tool and thats why its always stays 200/200.

My solutions for you are listed below:

  1. You can directly add a LocalScript inside the tool and getting tool and tool value with local Tool = script.Parent, because a LocalScript runs when it’s a descendant of the character or backpack. I assume your current LocalScript is not inside the tool.
  2. Update the ObjectValue on the server. When the new tool is cloned, set the ObjectValue to the new tool instead of the old one. The same ObjectValue doesn’t update automatically when the tool is cloned.
1 Like

Alright so I accidentally solved it myself while setting things up to try your solutions, turns out im just REALLY stupid… :man_facepalming:

I haven’t been cloning any new GUIs since I was trying to get it to work first, so I was just working with a GUI in StarterGui linked to the tool in StarterPack, and was under the interpretation that it was no different then a tool in the player’s character model (which is where it should be while in use). And it just hit me that the GUI was linked to the original StarterPack template, and not the tool that is handed out to me when I spawn in. :man_facepalming:

Basically I was just being comically stupid and forgot that tools in StarterPack are CLONED and placed in the backpacks of new players. This also explains why the RemoteEvent wasn’t being detected, as it wasn’t being sent through my copy of the tool, only the template. And it also explains why I never had any issues with this in previous projects, because I was actually using my brain before.

Placing the GUI in the tool (not StarterGui) and then cloning it and placing it in PlayerGui upon equip, as originally planned once the issue was fixed, fixed the issue 100%. :man_facepalming:

Thank you for trying to help, I really appreciate it. :smiling_face_with_tear:

1 Like

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