Still getting old value or nil when using getpropertychangedsignal for numbervalue

local tool = backpack:FindFirstChild(currentNet) or player.Character:FindFirstChild(currentNet)
player:WaitForChild("HiddenStats").CurrentNet:GetPropertyChangedSignal("Value"):Connect(function()

	replicatedStorage.RemoteEvents.UpdateNet.OnClientEvent:Connect(function(Net)
		tool = backpack:WaitForChild(Net) or player.Character:WaitForChild(Net)
		
		print(tool)
		print(tool.Parent)
	end)
	
end)

game.ReplicatedStorage.RemoteEvents.EquipNet:FireServer(tool, tool.Parent)  

tool.Parent prints nil and sometimes tool will print but it will only print the old value even if its changed

This should be as a separate function from itself, there’s no need to be nesting it inside your GetPropertyChangedSignal function

Also if this is a Value Object, you can just simply use the .Changed Event to detect when the Value changes instead of using GetPropertyChangedSignal, sure they work the same but .Changed is exclusively for this occasion

Also, your second or statement will not work because WaitForChild() is a yielding function, and will completely pause the script’s thread until a result has been found back

You can fix this by adding a Timeout on the second parameter, in case it returns back as nil

Also for me on how I would personally take this, I would just combine this into 1 main function and connect it onto 2 Events so that you can detect for both the .Changed Event, and when you detect OnClientEvent signals:

local replicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = replicatedStorage:WaitForChild("RemoteEvent")
local NetEvent = RemoteEvents:WaitForChild("UpdateNet")

local player = game.Players.LocalPlayer
local backpack = player:WaitForChild("Backpack")
local HiddenStats = player:WaitForChild("HiddenStats")
local CurrentNet = HiddenStats:WaitForChild("CurrentNet")

local Tool = backpack:FindFirstChild(CurrentNet) or player.Character:FindFirstChild(CurrentNet)

local function UpdateNet(Net)
    Tool = backpack:WaitForChild(Net, 1) or player.Character:WaitForChild(Net, 1)

    if Tool == nil then
        warn("Tool has not been inserted correctly!")
    end
end

NetEvent.OnClientEvent:Connect(UpdateNet)
CurrentNet.Changed:Connect(UpdateNet)

NetEvent:FireServer(Tool, Tool.Parent)

thank you for helping, the same error still happens and tool is still nil for some reason, on the server side of this its a shop and im buying or equipping my owned items and destroying all of them inside of the backpack already then replacing it with the newly bought item, its still trying to get the old item and also spitting this error out exception while signaling: The Parent property of Item is locked, current parent: NULL

for i,tool in pairs(player:WaitForChild("Backpack"):GetChildren()) do
				if tool:IsA("Tool") then
					tool:Destroy()
				end
			end

			local Net = game:GetService("ServerStorage").NetTools:FindFirstChild(player:WaitForChild("HiddenStats").CurrentNet.Value):Clone()
			Net.Parent = player:WaitForChild("Backpack")
			
			ReplicatedStorage.RemoteEvents:WaitForChild("UpdateNet"):FireClient(player, Net)

This is because you’re not implementing any sanity checks when you call FindFirstChild(), sure it might be able to properly find the object but if that line doesn’t work then your script will result in an error with no proper fix around it

Also, you’ll have to remove the Tool that the Player’s Character is holding as well when you loop through the Player’s Backpack but thankfully we have a function called Humanoid:UnequipTools(), so we can call that before we run our loop and it should work like this:

local Char = player.Character

if not Char then
    return
end

local HiddenStats = player:WaitForChild("HiddenStats")
local CurrentNet = player:WaitForChild("CurrentNet")
local Hum = Char:WaitForChild("Humanoid")
local Backpack = player:WaitForChild("Backpack")

Hum:UnequipTools()

for _, Object in pairs(Backpack:GetChildren()) do 
    if Object:IsA("Tool") then
        Object:Destroy()
    end
end

local Net = game:GetService("ServerStorage").NetTools:FindFirstChild(CurrentNet.Value)
-- KEEP IN MIND, THAT "Net" CAN RETURN 2 OPTIONS: "nil", or the Object found

if Net ~= nil then
    local Clone = Net:Clone()
    Clone.Parent = Backpack

    ReplicatedStorage.RemoteEvents:WaitForChild("UpdateNet"):FireClient(player, Clone)
end

if Tool == nil then
warn(“Tool has not been inserted correctly!”)
end

Tool is still nil even after doing all of this, idk why but its not finding the tool inside of the backpack or the character

So, apparently I didn’t see this but it doesn’t look like you’re changing the CurrentNet.Value whenever we find it that it’s valid on the server side

And on the client side, we can move our local Tool into our UpdateNet(Net) function so that we can properly call it whenever necessary

-- Client
local replicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = replicatedStorage:WaitForChild("RemoteEvent")
local NetEvent = RemoteEvents:WaitForChild("UpdateNet")

local player = game.Players.LocalPlayer
local backpack = player:WaitForChild("Backpack")
local HiddenStats = player:WaitForChild("HiddenStats")
local CurrentNet = HiddenStats:WaitForChild("CurrentNet")

--local Tool = backpack:FindFirstChild(CurrentNet) or player.Character:FindFirstChild(CurrentNet)

local function UpdateNet(Net)
    local Tool = backpack:WaitForChild(Net, 1) or player.Character:WaitForChild(Net, 1)

    if Tool == nil then
        warn("Tool has not been inserted correctly!")
    end
end

NetEvent.OnClientEvent:Connect(UpdateNet)
CurrentNet.Changed:Connect(UpdateNet)

UpdateNew(CurrentNet.Value) -- We actually want to call this once lol

NetEvent:FireServer(Tool, Tool.Parent)
-- Server
local Char = player.Character

if not Char then
    return
end

local HiddenStats = player:WaitForChild("HiddenStats")
local CurrentNet = player:WaitForChild("CurrentNet")
local Hum = Char:WaitForChild("Humanoid")
local Backpack = player:WaitForChild("Backpack")

Hum:UnequipTools()

for _, Object in pairs(Backpack:GetChildren()) do 
    if Object:IsA("Tool") then
        Object:Destroy()
    end
end

local Net = game:GetService("ServerStorage").NetTools:FindFirstChild(CurrentNet.Value)
-- KEEP IN MIND, THAT "Net" CAN RETURN 2 OPTIONS: "nil", or the Object found

if Net ~= nil then
    local Clone = Net:Clone()
    Clone.Parent = Backpack

    ReplicatedStorage.RemoteEvents:WaitForChild("UpdateNet"):FireClient(player, Clone.Name)
end

I’m unsure why it’s printing nil, but make sure for yourself to add some print() statements to further debug the issue

i really dont know know man, nothing is changing at all its still nil i have no idea why, its loading correctly, its actually there in the backpack but its still nil

Nvm, I think I found the issue

Try to replace this

With this instead:

    ReplicatedStorage.RemoteEvents:WaitForChild("UpdateNet"):FireClient(player, Clone.Name)

It’s weird how this doesn’t error considering that it’s expecting a string, and Clone is an Instance

1 Like

omg i cant believe it was something this simple, tysm for the help

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