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
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