Attempt to index number with number

Hello,
im creating a table, and i wanna put something at the end of it, works fine BUT if i remote it with a event, server script for example it says attempt to index number with number? Here is the script.

local CASES = {}
local main = script.Parent.ScrollingFrame
local numberRounds = 0
local numberCost = 0
local gameMode = "1v1v1"
local record = 1

main.IceCase.Button1.MouseButton1Click:Connect(function()
	numberRounds = numberRounds +1
	numberCost = numberCost +2014
	table.insert(CASES, "IceCase")
	record = record +1
	script.Parent.rounds.Text = "Rounds: "..numberRounds
	script.Parent.cost.Text = "Cost: "..numberCost
	local org = script.Parent.Parent.CaseInfo.ScrollingFrame.originIMG:Clone()
	org.Image = "rbxassetid://10910715327"
	org.Parent = script.Parent.Parent.CaseInfo.ScrollingFrame
	org.Name = "ClonedIMG"
end)

script.Parent.StartBattle.MouseButton1Click:Connect(function()
	if numberCost <= game.Players.LocalPlayer.leaderstats["Trading Bucks"].Value then
		game.ReplicatedStorage.caseBattles.createBattle:FireServer(game.Players.LocalPlayer, numberCost, numberRounds, CASES, gameMode)
	end
end)

Heres the serverscript, the error is at line 59

local iceCaseIMG = "rbxassetid://10910715327"

replicatedStorage.caseBattles.createBattle.OnServerEvent:Connect(function(Client, Cost, RoundAmount, case)
	local newTemp = game.StarterGui.UI.Dashboard.CaseBattles.ScrollingFrame.Template:Clone()
	newTemp.Visible = true
	newTemp.Name = "Battle"..Client.Name
	newTemp.playerName.Text = Client.Name.."'s Case Battle"
	newTemp.rounds.Text = tostring(RoundAmount)
	newTemp.Button1.itemPrice.priceAmt.Text = tostring(Cost)
	if case[1] == "IceCase" then -- ERROR HERE
		newTemp.BattlesContainerTemplate.originIMG.Image = iceCaseIMG
	end
1 Like

Simply, remove the localplayer argument from the fireserver call

createBattle:FireServer(game.Players.LocalPlayer, numberCost, numberRounds, CASES, gameMode)

(should be this)

createBattle:FireServer(numberCost, numberRounds, CASES, gameMode)

Since onserverevent recieves the player that fired it AUTOMATICALLY you don’t need to pass the localplayer in fireserver.

P.S: As a more direct answer to your question, OnServerEvent is recieving the numberRounds from the fireserver AS the cases, since you put in the extra localplayer argument.
What you passed:

createBattle:FireServer(game.Players.LocalPlayer, numberCost, numberRounds, CASES, gameMode)

What the server actually sees

createBattle.OnServerEvent:Connect(function(Client, ClientAgain, numberCost, numberRounds, cases, gamemode)
1 Like

Once again rushed :stuck_out_tongue_winking_eye:
Thank you!

1 Like