Argument 1 is missing or nil

I’m trying out InsertService on a OnServerEvent, but keep running into the error “Argument 1 is missing or nil” whenever it is activated. For context, this is apart of a character customization system I’ve been working on for my game. I’ve looked for solutions across the forums but haven’t found anything more applicable to my scenario, or at least so I think. Any help figuring this out will be appreciated!

LocalScript

shirts.NameButton.Activated:Connect(function()
	clothingEvent:FireServer(player, "Customization")
	renderPlayer()
end)

ServerScript

local InsertService = game:GetService("InsertService")

local clothingEvent = game.ReplicatedStorage.remoteEvents.clothingEvent
local clothesData = require(game.ReplicatedStorage.Modules.Data.clothesData)

clothingEvent.OnServerEvent:Connect(function(player, eventtype)
	local character = player.Character
	local shirt = character:WaitForChild("Shirt")
	local pants = character:WaitForChild("Pants")
	print(character:GetChildren())
	shirt.ShirtTemplate = InsertService:LoadAsset(tonumber(clothesData.Asset)).Shirt.ShirtTemplate
	print("Changed shirt to:", clothesData.DisplayName)
	clothingEvent:FireClient(player, "Customization")
end)

You don’t have to pass the player when Firing a remote, the server knows already, so just pass your own needed args

3 Likes

I wasn’t aware of this, thanks for pointing it out!

1 Like

I am not sure if this is the problem, but I think clothesData.Asset is a real number and not nil.

local assetId = clothesData.Asset
if not assetId then
	warn("Missing Asset ID in clothesData!")
	return
end

local asset = InsertService:LoadAsset(assetId)
local shirtAsset = asset:FindFirstChildOfClass("Shirt")
if shirtAsset then
	shirt.ShirtTemplate = shirtAsset.ShirtTemplate
end

Looks like this is just a snippet. Are you using WaitForChild() on any of this before hand?
Is this “clothesData.Asset” a .Value that needs to be read?

local rep = game:GetService("ReplicatedStorage")
local clothesData = rep:WaitForChild("clothesData")
local assetId = clothesData:WaitForChild("Asset").Value

WaitForChild isn’t necessarily a huge pause; it’s more like as fast as possible.
Nil usually means it’s not there or hasn’t loaded yet, or is being called incorrectly.