Tool not going into StarterGear

Hello there,

I made a Tool Select UI which lets you select which Tool you want to use instead of me putting it into the starterpack. It goes into your backpack but after you respawn it disappears. I tried to make it go into the StarterGear so that it won’t disppear but now it doesn’t work. Did I do something wrong?

Code
local ToolName = "Tool"
local Player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")




script.Parent.MouseButton1Click:connect(function()
    
    if ReplicatedStorage:FindFirstChild(ToolName) then
                if not Player.Backpack:FindFirstChild(ToolName) then
                    local Tool = ReplicatedStorage:WaitForChild(ToolName):Clone()
                    Tool.Parent = Player.StarterGear
		
		
		
		end


            end
        
  
    end)

It does work (try respawning), but when something gets put into StarterGear, it doesn’t get put into the Backpack. If you know how StarterGui & PlayerGui work, it’s the same deal.

The solution is to simply clone it into both:

local Tool = ReplicatedStorage:WaitForChild(ToolName)
Tool:Clone().Parent = Player.StarterGear
Tool:Clone().Parent = Player.Backpack

(:Clone() returns the new object so you can shorthand it by setting the parent in the same statement.)


Also, you’re formatting needs some work :wink:

Try to use as few lines as possible, and only use empty lines for separating different groups of statements.
Make sure all of your ends and statements are in the right indentation, too.

local ToolName = "Tool"
local Player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.MouseButton1Click:connect(function()
    local Tool = ReplicatedStorage:FindFirstChild(ToolName) -- you only need to do this once!

    if Tool and not Player.StarterPack:FindFirstChild(ToolName) then -- you can do two checks in one statement
        Tool:Clone().Parent = Player.StarterGear
        Tool:Clone().Parent = Player.Backpack
    end
end)
8 Likes

Thanks, it worked!

1 Like