Hi, I am trying to make an upgrade system, I put the player’s upgrades into a table and when I go to upgrade the item I get the error, [attempt to index field ‘?’ (a nil value), anybody know what the problem is?
functions["Upgrade"].OnServerInvoke = function(player, Info)
print(_G.Data[player.Name]["Upgrades"][Info.Stat][1])
if _G.Data[player.Name]["Upgrades"][Info.Stat] then
if _G.Data[player.Name]["Coins"] >= _G.Data[player.Name]["Upgrades"][Info.Stat][4] then
_G.Data[player.Name]["Coins"] = _G.Data[player.Name]["Coins"] - _G.Data[player.Name]["Upgrades"][Info.Stat][4]
_G.Data[player.Name]["Upgrades"][Info.Stat][4] = _G.Data[player.Name]["Upgrades"][Info.Stat][4] + _G.Data[player.Name]["Upgrades"][Info.Stat][5]
_G.Data[player.Name]["Upgrades"][Info.Stat][1] = _G.Data[player.Name]["Upgrades"][Info.Stat][1] + _G.Data[player.Name]["Upgrades"][Info.Stat][2]
player["leaderstats"]["Coins"].Value = _G.Data[player.Name]["Coins"]
end
local data = {}
data["Cost"] = _G.Data[player.Name]["Upgrades"][Info.Stat][4]
data["UpgradeValue"] = _G.Data[player.Name]["Upgrades"][Info.Stat][1]
return data
end
end
this is where it is erroring print(_G.Data[player.Name]["Upgrades"][Info.Stat][1])
this is what the client is sending
for _,v in pairs(script.Parent:GetChildren()) do
if v:IsA("Frame") then
v.Buy.Activated:Connect(function()
if deb == false then deb = true
local returnedStats = functions["Upgrade"]:InvokeServer({tonumber(v)})
print(v)
if v == "Chance" then
v.Need.Text = returnedStats.UpgradeValue.."% Chance Per Click"
elseif v == "CoinsPerCritical" then
v.Need.Text = "+"..returnedStats.UpgradeValue.." Coins Per Click"
end
v.Buy.UpgradeText.Text = "UPGRADE - "..returnedStats.Cost.."Coins"
wait(0.5)
deb = false
end
end)
end
end
I am trying to get the name of the upgrade, so there are frames in the upgrade gui, so when the player clicks one of the frame’s upgrade button it will fire the name of the frame which is one of stats, “Chance” or “CoinsPerCritical”
also changed it back to tostring(), still getting the same error
You don’t receive a correct value there then if the value it’s nil and it errors there. May I ask why are you Invoking number to server in curly brackets?
I fire arguements into a table so I can just call it Info on the server script,so if I got more arguements to send out I can just do something like Info.FrameName on the serverside
now I am getting the error, Players.CleanVac.PlayerGui.MainGui.Frames.Upgrade.UpgradeFrame.LocalScript:17: attempt to index local ‘returnedStats’ (a nil value)
error line v.Buy.UpgradeText.Text = "UPGRADE - "..returnedStats.Cost.."Coins"