Argument 2 Missing or Nil

For some reason, I think the code is not working, but I don’t know why, I think it should work, and it prints the vehicle name, just take a look…?
CLIENTSIDE: NO ERROR HERE

local Index = 1
local MaxIndex,MinIndex,OldCar,Camera
local Player = game:GetService("Players").LocalPlayer

local Items = {

}

function SetReadyItems()
	for i,v in ipairs(game.ReplicatedStorage.FakeCars:GetChildren()) do
		if v then
			Items[#Items + 1] = {Name=v.Name, Price=v.Price.Value}
			print(Items[i].Name)
		end
	end
	wait()
	MaxIndex = #Items
	MinIndex = 1
	print(#Items)
	
end



function Next()
	Index = Index + 1
	if Index > MaxIndex then
		Index = 1
	end
	RefreshIndex()
end



function Back()
Index = Index - 1
if Index < MinIndex then
	Index = MaxIndex
end
RefreshIndex()
end

function SetCamera()
	local camera = workspace.CurrentCamera
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = workspace.Buildings.Dealership.MainView.CFrame
Camera = camera
end

SetReadyItems()

repeat
	SetCamera()
	wait()

until Camera.CFrame == workspace.Buildings.Dealership.MainView.CFrame or Camera.CameraType == Enum.CameraType.Scriptable

function Close()
	if OldCar then
		OldCar:Destroy()
	end
	local camera = workspace.CurrentCamera
	camera.CameraType = Enum.CameraType.Custom
end

script.Parent.Purchase.MouseButton1Click:Connect(function()
	if script.Parent.Button.Text == "PURCHASE" then
	local Vehicle = Items[Index]
	if Player["leaderstats"]['Bank'].Value >= Vehicle.Price then
		script.Parent.Button.Text = "SPAWN"
		print(Items[Index].Name)
		game.ReplicatedStorage.BuyCar:FireServer(Vehicle.Name)
		elseif Player["leaderstats"]['Bank'].Value < Vehicle.Price then
			script.Parent.Button.Text = "YOU NEED MORE CASH"
			wait(1)
			script.Parent.Button.Text = "PURCHASE"
	end
	elseif script.Parent.Button.Text == "SPAWN" then
		local Vehicle = Items[Index]
		game.ReplicatedStorage.SpawnCar:InvokeServer(Vehicle.Name)
	end
end)

function RefreshIndex()
	if OldCar then
		OldCar:Destroy()
	end
	local Vehicle = Items[Index]
	local ToClone = game.ReplicatedStorage.FakeCars:FindFirstChild(Vehicle.Name):Clone()
	ToClone.Parent = workspace.CurrentCamera
	OldCar = ToClone
	script.Parent.CarName.Text = Vehicle.Name
	local Owned = game.ReplicatedStorage.OwnCar:InvokeServer(Vehicle.Name)
	if Owned == true then
		script.Parent.Button.Text = "SPAWN"
	elseif not Owned then
			script.Parent.Button.Text = "PURCHASE"
	end
end

RefreshIndex()

script.Parent.Next.MouseButton1Click:Connect(Next)
script.Parent.Back.MouseButton1Click:Connect(Back)

SERVERSIDE: ERROR HERE
AT LINE 25.


	game:GetService("ReplicatedStorage").BuyCar.OnServerEvent:Connect(function(Player, Item)
		if Item then
		local ItemPrice = AllItems[Item]
		print(tostring(ItemPrice))
		if not Data:GetAsync(Player.UserId.."-"..Item) then
		print(Item)
			if Player['leaderstats']['Bank'].Value >= ItemPrice then
				Data:SetAsync(Player.UserId.."-"..Item) -- HERE IS ERROR, any idea?
				end 
				end
			end
		end)

The error is at :SetAsync()

Roblox is currently unavailable, so you can’t connect to the service.

Because SetAsync requires two parameters.

2 Likes

Oh, so it’s because the same error as before