Hi there! I am trying to update my ModuleScript locally (I have got it set up to update on the server-side and am just trying to replicate it locally).
The way I am currently trying to do this is by firing a RemoteEvent to all clients in the ServerScript, however for some reason the variable that I’m sending from the ServerScript to the LocalScript is returning as a hex value.
My output:
19:56:12.757 ▼ {
["Colour"] = 0.0588235, 0, 0.509804,
["Description"] = "An enforcer of the law. Keeps the peace.",
["Max"] = 20,
["Total"] = 1,
["Value"] = 1200
} - Server - RemoteFunctions:20
19:56:12.790 table: 0xd3dc9037780ae132 - Client - MenuController:20
19:56:12.790 Players.StrayanCini.PlayerGui.MenuUI.MenuController:21: attempt to index nil with 'Total' - Client - MenuController:21
Here is the ServerScript (RemoteFunctions):
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Jobs = require(ReplicatedStorage.jobs)
local oldJob = nil
function changeJob(player, job)
local prevJob = Players[player.Name].leaderstats.Job
oldJob = tostring(prevJob.Value)
if Jobs[job].Total >= Jobs[job].Max then return end
if job == prevJob.Value then return end
Jobs[prevJob.Value].Total -= 1
print(prevJob.Value, Jobs[prevJob.Value].Total)
Players[player.Name].leaderstats.Job.Value = job
Jobs[job].Total += 1
print(job, Jobs[job].Total)
local curTotal = Jobs[job]
local prevTotal = Jobs[oldJob]
print(curTotal) -- THIS IS LINE 20
ReplicatedStorage.Remotes.ModuleUpdate:FireAllClients(curTotal, prevTotal)
end
ReplicatedStorage.Remotes.JobChange.OnServerInvoke = changeJob
The relevant parts of the LocalScript (MenuController):
local moduleUpdate = ReplicatedStorage.Remotes.ModuleUpdate
moduleUpdate.OnClientEvent:Connect(function(curTotal, prevTotal)
--print("Current Totals: " ..Jobs[curTotal].Total, curTotal.Total)
--print("Previous Totals: " ..Jobs[prevTotal].Total, prevTotal.Total)
print(tostring(curTotal)) -- THIS IS LINE 20
Jobs[curTotal].Total = curTotal.Total -- THIS IS LINE 21
Jobs[prevTotal].Total = prevTotal.Total
--print("Current Totals: " ..Jobs[curTotal].Total, curTotal.Total)
--print("Previous Totals: " ..Jobs[prevTotal].Total, prevTotal.Total)
end)
One of the tables in the ModuleScript just for context:
local jobs = {
["Police Officer"] = {
["Value"] = 1200,
["Colour"] = Color3.new(0.0588235, 0, 0.509804),
["Description"] = "An enforcer of the law. Keeps the peace.",
["Total"] = 0,
["Max"] = 20
},
}
return jobs