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!