Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My F3X Giver Command Doesn't Work, How do I fix this F3X command giver script?

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)

2 comments

0

Are you getting any errors in the output?

0

Oh, you can't do .Parent on a read-only table which is what :GetChildren() does. I don't think you can even use :GetChildren() until the asset is loaded. One moment while I check.

2 answers

Edit: Tool may not be the first index

Question

My F3X Giver Command Doesn't Work, How do I fix this F3X command giver script?

What Is Wrong

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.

Solution

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

Reading Resources

https://developer.roblox.com/en-us/api-reference/function/Instance/WaitForChild https://developer.roblox.com/en-us/api-reference/function/Instance/GetChildren

3 comments

1

Shouldn't always assume the first item in the model will be the tool. Might I suggest some form of verification such as the :IsA with a comparison selection. Additionally, to avoid issue should the first object not be a tool, maybe try a for loop with the selection statement suggested?

0

Thanks, Mega! I updated my post

0

It works in studio but not in game. : |

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)

1 comment

0

It didn't work.

This discussion is preserved as it was. New answers, comments, and votes are closed.