Firstly… Idk if this is the right topic. So please move this topic if it is the wrong category!
I have a game and I published the game to another game, but for some reason… one of the games have an error and the other one does not have an error, even though the games are the same.
Here is a video of what I mean:
Can someone tell me what is happening? And how to fix it?
local parent = script.Parent
local mainFrame = parent:WaitForChild("MainWorFrame")
local close = mainFrame:WaitForChild("Close")
local mainFrm = script.Parent:WaitForChild("MainFrame")
local scroller = mainFrm:WaitForChild("Scroller")
local open = scroller:WaitForChild("Workers"):WaitForChild("Button")
local shopFrame = mainFrame:WaitForChild("ShopFrame")
local replicatedStorage = game:GetService("ReplicatedStorage")
local AIRemotes = replicatedStorage:WaitForChild("AIRemoteEvents")
local removeWorkerFailedRemote = AIRemotes:WaitForChild("RemoveWorkerFailed")
local removeWorkerRemote = AIRemotes:WaitForChild("RemoveWorker")
local addWorkerRemote = AIRemotes:WaitForChild("AddWorker")
local addWorkerFailedRemote = AIRemotes:WaitForChild("AddWorkerFailed")
local alert = parent:WaitForChild("Alert")
local warningIcon = "http://www.roblox.com/asset/?id=2130987057"
local warningDuration = 30
local toNum = tonumber
local AIValues = replicatedStorage:WaitForChild("AIValueSettings")
local maxAIs = AIValues:WaitForChild("MaxAIs").Value
local receiveTable = AIRemotes:WaitForChild("SendTable")
local hiredWorkers = {}
local totalWorkers = 0
removeWorkerFailedRemote.OnClientEvent:Connect(function(title, reason)
game:GetService("StarterGui"):SetCore("SendNotification", {
Title = title;
Text = reason;
Icon = warningIcon;
Duration = warningDuration
})
alert:Play()
end)
addWorkerFailedRemote.OnClientEvent:Connect(function(title, reason)
game:GetService("StarterGui"):SetCore("SendNotification", {
title = title;
Text = reason;
Icon = warningIcon;
Duration = warningDuration
})
alert:Play()
end)
function increaseWorkers(worker, workerAmountLabel)
if totalWorkers < maxAIs then
workerAmountLabel.Text = workerAmountLabel.Text + 1
addWorkerRemote:FireServer(worker.Name)
end
end
receiveTable.OnClientEvent:Connect(function(tbl)
hiredWorkers = tbl
for i, v in ipairs(tbl) do
if i > 2 then
totalWorkers = v
end
end
for i, v in ipairs(shopFrame:GetChildren()) do
if not v:IsA("UIListLayout") then
v:WaitForChild("HiredWorkers").Text = hiredWorkers[i + 2]
end
end
end)
function decreaseWorkers(worker, workerAmountLabel)
if toNum(workerAmountLabel.Text) > 0 then
workerAmountLabel.Text = workerAmountLabel.Text - 1
removeWorkerRemote:FireServer(worker.Name)
end
end
for i, v in pairs(shopFrame:GetChildren()) do
if not v:IsA("UIListLayout") then
local b = v:FindFirstChild("AddWorkers")
if b then
b.MouseButton1Click:Connect(function()
increaseWorkers(v, v:WaitForChild("HiredWorkers"))
end)
end
end
end
for i, v in pairs(shopFrame:GetChildren()) do
if not v:IsA("UIListLayout") then
local b = v:WaitForChild("SubtractWorkers")
if b then
b.MouseButton1Click:Connect(function()
decreaseWorkers(v, v:WaitForChild("HiredWorkers"))
end)
end
end
end
open.MouseButton1Click:Connect(function()
mainFrame.Visible = not mainFrame.Visible
mainFrm.Visible = not mainFrm.Visible
end)
close.MouseButton1Click:Connect(function()
mainFrame.Visible = false
mainFrm.Visible = true
end)
Apparently you are having problems in this line. Since you, or your script, are trying to put a nil value as text. And hiredworkers seem to be a value that comes from the server. hiredWorkers = tbl
Could it be that you are forgetting to send some data from the server?
In case the event is correctly invoked by the server, towards the client. You can do this to make sure you’re not trying to put a nil value as text.
for i, v in ipairs(shopFrame:GetChildren()) do
if not v:IsA("UIListLayout") and hiredWorkers ~= nil then
v:WaitForChild("HiredWorkers").Text = tostring(hiredWorkers[i + 2]) -- I'm not sure if tostring() can solve this, but just in case, I add it.
end
end
I don’t think it’s a problem related to the publication of the game. I think it’s a problem, either from Studio, or from the script. I mean, that the script, on the server, is sending a nil value to the client, for whatever reason.
Since the game is completely the same, that should not cause this.
local replicatedStorage = game:GetService("ReplicatedStorage")
local AIremoteEvents = replicatedStorage.AIRemoteEvents
local addWorkerRemote = AIremoteEvents.AddWorker
local removeWorkerRemote = AIremoteEvents.RemoveWorker
local addWorkerFailedRemote = AIremoteEvents.AddWorkerFailed
local removeWorkerFailedRemote = AIremoteEvents.RemoveWorkerFailed
local dataStoreService = game:GetService("DataStoreService")
local hiredWorkersData = dataStoreService:GetDataStore("Hired Workers")
local players = game:GetService("Players")
local plotsOfLand = workspace.Plots
local workerTypes = {"Guards", "Cashier"}
local hiredData = {}
local err = error
local oneOfEachWorker = #workerTypes
local maxWorkers = replicatedStorage.AIValueSettings.MaxAIs.Value
local AICollision = require(script.AICollisions)
local sendTableRemote = AIremoteEvents.SendTable
local defaultTable = {0, 0}
players.PlayerAdded:Connect(function(plr)
local key = "key-"..plr.UserId
local data
local success, errorDebug = pcall(function()
data = hiredWorkersData:GetAsync(key)
end)
if success then
if data then
table.insert(hiredData, data)
else
data = {plr.UserId, 0}
for i, v in ipairs(defaultTable) do
table.insert(data, v)
end
table.insert(hiredData, data)
end
else
err(errorDebug)
end
sendTableRemote:FireClient(plr, data)
end)
players.PlayerRemoving:Connect(function(plr)
local key = "key-"..plr.UserId
local tbl
local index
for i, v in pairs(hiredData) do
if v[1] == plr.UserId then
tbl = v
index = i
break
end
end
local success, errorDebug = pcall(function()
if tbl and index then
hiredWorkersData:UpdateAsync(key, function(oldData)
local data = {}
local previousData
for i = 1, #workerTypes + 2 do
table.insert(data, 0)
end
previousData = oldData or data
if tbl[2] == previousData[2] then
tbl[2] = tbl[2] + 1
return tbl
else
return nil
end
end)
end
end)
if success then
print("Successfully saved hire Data!")
else
err(errorDebug)
end
end)
addWorkerRemote.OnServerEvent:Connect(function(player, worker)
if worker then
local tableIndex = 1
local tbl
for i, v in ipairs(hiredData) do
if v[1] == player.UserId then
tbl = v
tableIndex = i
break
end
end
local workerfound = false
local techicalIndex = 1
local index = 1
for i, v in ipairs(workerTypes) do
if v == worker then
workerfound = true
techicalIndex = i
index = i + 1
end
end
if workerfound then
local totalWorkers = 0
for i, v in ipairs(tbl) do
if i > 2 then
totalWorkers = totalWorkers + v
end
end
if totalWorkers < maxWorkers then
hiredData[tableIndex][index + 1] = hiredData[tableIndex][index + 1] + 1
else
addWorkerFailedRemote:FireClient(player, "Error!", "You can't have more than 25 total workers!")
end
if totalWorkers > maxWorkers then
player:Kick("Nice try with your exploiting. ;)")
end
sendTableRemote:FireClient(player, tbl)
else
player:Kick("Nice try. ;)")
end
else
player:Kick("Gotcha! ;)")
end
end)
removeWorkerRemote.OnServerEvent:Connect(function(player, worker)
if worker then
local tableIndex = 1
local tbl
for i, v in ipairs(hiredData) do
if v[1] == player.UserId then
tbl = v
tableIndex = i
break
end
end
local workerfound = false
local techicalIndex = 1
local index = 1
for i, v in ipairs(workerTypes) do
if v == worker then
workerfound = true
techicalIndex = i
index = i + 1
end
end
if workerfound then
local totalWorkers = 0
for i, v in ipairs(tbl) do
if i > 2 then
totalWorkers = totalWorkers + v
end
end
if totalWorkers > 0 then
hiredData[tableIndex][index + 1] = hiredData[tableIndex][index + 1] - 1
else
addWorkerFailedRemote:FireClient(player, "Error!", "You can't have less than 0 worker(s)")
end
if totalWorkers < 0 then
player:Kick("Nice try with your exploiting. ;)")
end
sendTableRemote:FireClient(player, tbl)
else
player:Kick("Nice try. ;)")
end
else
player:Kick("Gotcha! ;)")
end
end)
Note that the script is an unfinished AI / NPC script.
I have the same problem but listen or read lmao so i think this error because you fast close the roblox studio after you stop playing i can happen some times after you publish or create a model so just after publish create a model or stop playing wait five or ten seconds and the game can not save hope this post is helpful