I have been struggling on why my arrays aren’t updating to the value assigned by the Remote Event. I have a Server Script pass an array copy to the client that already has variables ready to copy the contents of the server’s array. My code is below. Whenever it runs, I get the value of senderHats is 0, so I know that the value isn’t being passed. Help is greatly appreciated!
CLIENT
--[[RECEIVER]]--
--[[Services]]--
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--[[Remote Events]]--
local receiveTradeEvent = ReplicatedStorage.RemoteEvents:WaitForChild("ReceiveTradeEvent")
--[[Variables]]--
local button = script.Parent
local opened = false
local player = Players.LocalPlayer
local tradeRequestWindow = player.PlayerGui:WaitForChild("TradeGui").TradeMenu.TradeRequest
local updateHats = false
--[[Hats requested from player]]--
local senderHats = {}
--[[Hats the player is willing to give]]--
local receiverHats = {}
-- Upload the hats in the trade to the trade request window --
button.MouseButton1Up:Connect(function()
print(#senderHats)
for i = 1, #senderHats do
senderHats[i].Parent = tradeRequestWindow.ReceivedHats
print(senderHats[i].Name)
end
for i = 1, #receiverHats do
receiverHats[i].Parent = tradeRequestWindow.RequestedHats
print(receiverHats[i].Name)
end
tradeRequestWindow.Visible = true
-- Remove the trade request when opened to prevent complexities --
button:Destroy()
end)
receiveTradeEvent.OnClientEvent:Connect(function(sHats, rHats)
for i = 1, #sHats do
table.insert(senderHats, sHats[i])
end
for i = 1, #rHats do
table.insert(receiverHats, rHats[i])
end
end)