I'm trying to make a command that gives me F3X (the FE version) but it doesn't give the the tool. I need help fixing this.
Here's the script:
game:GetService("Players").PlayerAdded:Connect(function(player) if player.UserId == 20640392 then -- Only this UserId can run the command. player.Chatted:Connect(function(message) if message == "/givemef3x" then local F3X = game:GetService("InsertService"):LoadAsset(142785488):GetChildren() F3X:Clone().Parent = player.Backpack -- Copy the F3X into the backpack. end end) end end)
Edit: Tool may not be the first index
My F3X Giver Command Doesn't Work, How do I fix this F3X command giver script?
If we look at line 5
and 6
,
local F3X = game:GetService("InsertService"):LoadAsset(142785488):GetChildren() F3X:Clone().Parent = player.Backpack
:LoadAsset()
returns a model
containing the asset(s) you're attempting to load.
You will see that F3X
is set to the array
returned from the :GetChildren()
method. When you try to call :Clone()
it will error because the array likely doesn't have the :Clone()
method as an index.
I believe you're trying to clone the child which is the tool into the player
's backpack, which will be one of the indexes in the array returned. You can find it by iterating over the array.
Set F3X
to the index which is the tool inside the array returned from :GetChildren()
and then set it's parent to the player's backpack. (You don't need to clone it in this scenario)
local assets = game:GetService("InsertService"):LoadAsset(142785488):GetChildren() --// Load the asset and then get children of the returned model. local F3X --// define variable for what the tool will be referenced as for i, asset in pairs(assets) do if asset:IsA("Tool") then --// is this asset a tool? F3X = asset --// if its a tool then variable `F3X` is set to it. end end F3X.Parent = player:WaitForChild("Backpack") --// parent the tool to the player's backpack when it finally exists
https://developer.roblox.com/en-us/api-reference/function/Instance/WaitForChild https://developer.roblox.com/en-us/api-reference/function/Instance/GetChildren
game:GetService("Players").PlayerAdded:Connect(function(player) if player.UserId == 20640392 then -- Only this UserId can run the command. player.Chatted:Connect(function(message) if message:match("/givemef3x") then--simple fix, see if it matches instead local F3X = game:GetService("InsertService"):LoadAsset(142785488):GetChildren() F3X:Clone().Parent = player.Backpack -- Copy the F3X into the backpack. end end) end end)