I’m trying to make an admin system including a :gear command. It is almost complete but InsertService is not inserting the gear that I select when in the script, even though the exact same line works in the command bar in studio.
function commands.gear(plr, giveplr, id)
if allowed(plr) >= tonumber(3) then
local plrToGive = getPlayer(plr, giveplr)
if plrToGive then
if plrToGive == "all" then
for i,v in ipairs(players:GetPlayers()) do
local gear = IS:LoadAsset(id)
gear.Parent = plr.Backpack
end
elseif plrToGive == "others" then
for i,v in ipairs(players:GetPlayers()) do
if v ~= plr then
local gear = IS:LoadAsset(id).Parent = workspace
gear.Parent = plr.Backpack
end
end
else
local gear = IS:LoadAsset(id)
print(gear.Parent)
gear.Parent = plr.Backpack
print(gear.Parent)
end
end
end
end
InsertService only works if you own the asset or if it’s a official Roblox item. What are you trying to load? Also this can help: InsertService:LoadAsset
Why is there a parent assignment here, shouldn’t that cause an error?
My only idea as to why it isn’t working is that it’s either not going into the LoadAsset part, or something is wrong with the ID itself, which is the more likely issue. How are you passing in the id? May we see the section of code where you call commands.gear
Thing is they were doing it whilst trying assign it to a variable, if it was just IS:LoadAsset(id).Parent = workspace it would work, but they’re assigning it to a gear variable
if string.find(message, prefix) then
local starts, ends = string.find(message, prefix)
local mwp = string.sub(message, ends + 1, #message)
local args = string.split(mwp, " ")
local command = args[1]
if commands[command] then
table.remove(args, 1)
commands[command](player, table.unpack(args))
end
end
I think your issue is that the ID is still a string since I don’t see any tonumber there, try converting id to a number before any of the LoadAsset in your commands.gear