I’m trying to pass a table from my script to a localscript, and it’s partially working. The problem is, I have values in the table that are assigned to be equal to numValues that are placed in ServerStorage. When I want to print out the “.Value” of the numbers (from the table) in the localscript (after receiving the remote event) it gives me the error, "attempt to index nil with ‘Value’ ".
EDIT: Quick note. When I click the button, it prints out “1 nil”, which is the first .Name, then gives me that error.
So the main thing I’m trying to accomplish is the following. To have the script that has the table pass that table to the client, then have the client loop through the table and print out every one of the “Name” and “Time.Value” in that table.
I’m speculating that it’s because the values that are in the table are assigned to be equal to numbers in ServerStorage. Thus, when I try to do “.Value” on them from the localscript, it can’t find the values due to them being in ServerStorage. Interestingly enough, when I go to the table (in the server script) and change the numbers from “Time = Time1” to “Time = Time1.Value”, now it works! But I can’t do that, due to me using .Changed in the system I’m creating. Any ideas? Here’s sections of the code:
Script (Placed In ServerScriptService):
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
-- Variables
local GuiEvent = ReplicatedStorage:WaitForChild("RaceStats")
local Time1 = ServerStorage.PlayerTimes.Time1
local Time2 = ServerStorage.PlayerTimes.Time2
local Time3 = ServerStorage.PlayerTimes.Time3
local Time4 = ServerStorage.PlayerTimes.Time4
-- Creates Main Table
local PlayerAssignments = {
{Name = "1nil", Time = Time1, Bool = RacingBool1},
{Name = "2nil", Time = Time2, Bool = RacingBool2},
{Name = "3nil", Time = Time3, Bool = RacingBool3},
{Name = "4nil", Time = Time4, Bool = RacingBool4}
}
GuiEvent.OnServerEvent:Connect(function()
GuiEvent:FireAllClients(PlayerAssignments)
end)
LocalScript (Placed In Gui Under Button):
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Variables
local button = script.Parent
local StatsRemote = ReplicatedStorage:WaitForChild("RaceStats")
button.MouseButton1Click:Connect(function()
StatsRemote:FireServer()
end)
StatsRemote.OnClientEvent:Connect(function(PlayerAssignments)
for Var, Players in pairs(PlayerAssignments) do
print(Players.Name)
print(Players.Time.Value)
end
end)
Thanks for any help!