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

How to add a tool in a backpack when you spawn?

Asked by
Xyternal 247 Moderation Voter
2 years ago

I am trying to make a local script to add a tool in your back pack when I click a button. When I run my script, and spawn in, I get nothing when I click. Why? Here is my script.

local StarterGui = game:GetService('StarterGui') 
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character.Humanoid

local WEAPON = Player.Backpack['M16'] 


local HumanoidRootPart = Character:WaitForChild('HumanoidRootPart')

local GotGun = false
local btn = game.StarterGui.ScreenGui.Frame.TextButton

btn.MouseButton1Click:Connect(function()



        if GotGun == false then
            Humanoid:EquipTool(WEAPON)
            GotGun = true
        end

end)
if Humanoid.Health == 0 then


    Humanoid:UnequipTools()

    GotGun = false
end

1 answer

Log in to vote
0
Answered by
bdam3000 125
2 years ago

When a player loads into the game, a folder is parented to the player named "PlayerGui"

Everything from StarterGui is cloned into PlayerGui. Everything in that folder are the GUIs that the player actually sees.

Change line 14 to this,

local btn = Player.PlayerGui.ScreenGui.Frame.TextButton
0
wait do u have discord? i kinda wanna carry our converstation there cuz i got a change of plans Xyternal 247 — 2y
0
sorry for the late reply, I don't check this site often. It's bdam#1716 bdam3000 125 — 2y
Ad

Answer this question