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

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

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

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

2 comments

0

wait do u have discord? i kinda wanna carry our converstation there cuz i got a change of plans

0

sorry for the late reply, I don't check this site often. It's bdam#1716

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