Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago
Edited by theking48989987 5 years ago

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)
0
Are you getting any errors in the output? M39a9am3R 3210 — 5y
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. M39a9am3R 3210 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

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? M39a9am3R 3210 — 5y
0
Thanks, Mega! I updated my post EpicMetatableMoment 1444 — 5y
0
It works in studio but not in game. : | lISpider_ManIl -5 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
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)
0
It didn't work. lISpider_ManIl -5 — 5y

Answer this question