I’m making a script which produces the sum of all intvalues in a folder (the inventory). Whenever an intvalue changes, a .Changed event is triggered which causes the RemoteEvent to fire to a server script which adds all the values in the inventory. This then updates that value in a module script. The prints in the script all come back as zero. This is particularly strange given that I manually change one item.Value to be 1000. It also prints everything every time I change a value. Is this because of the way I’m using remote events maybe?
local repStor = game:GetService("ReplicatedStorage")
local PackStorage = repStor.Remotes.PackStorage
local ServerStorage = game:GetService("ServerStorage")
local modules = ServerStorage.Modules
local Values = modules.Values
local Values = require(Values)
PackStorage.OnServerEvent:Connect(function(player)
local Inventory = player.Inventory
local SumValue = 0
for _,item in pairs(Inventory:GetChildren()) do
SumValue = item.Value + SumValue
print(item.Value)
print(SumValue)
end
Values.Packs.PackSpace = SumValue
print(SumValue)
end)
2 Likes
So a local script is firing the remote event? Does a number print when you manually change something?
1 Like
Yes, a local script in PlayerGUI is firing the remote event every time a value is changed. When I manually change the number (via the server) it still prints 0.
1 Like
It should work. Can you show us the local script?
1 Like
Sure. The local script is essentially just a jumble of different GUI functions.
local repStor = game:GetService("ReplicatedStorage")
local PackStorage = repStor.Remotes.PackStorage
local players = game:GetService("Players")
local player = players.LocalPlayer
local leaderstats = player.leaderstats
local Inventory = player.Inventory
local Cash = leaderstats.Cash
local MainGUI = script.Parent
local CashLabel = MainGUI.CashLabel
local InventoryButton = MainGUI.InventoryButton
local InventoryGUI = MainGUI.Parent:WaitForChild("InventoryGUI")
InventoryButton.MouseButton1Up:Connect(function()
InventoryGUI.Enabled = true
MainGUI.Enabled = false
end)
Cash.Changed:Connect(function(newvalue)
CashLabel.Text = Cash.Value
end)
for _,v in pairs(Inventory:GetChildren()) do
v.Changed:Connect(function(newvalue)
PackStorage:FireServer(player)
end)
end
The only relevant part is the for loop at the end.
The ‘Inventory’ folder is something created in a different script.
I’m really not sure man. It should work, well for me at least. Are you sure you manually change the values by the SERVER not the Client?
1 Like
It has the same effect if I change it via the client. It prints 0 if I change it via the server anyway, so that shouldn’t be the issue.
1 Like