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

Equipping a tool?

local Player = game.Players.LocalPlayer
local gun = game.Player.Backpack:WaitForChild("PSTL")


gun.Equipped:connect(function(mouse)
Player.PlayerGui.ScreenGui.Frame.TextLabel.Text = "PSTL"
end)

I'm having troubles with changing the text of a TextLabel when a tool is equipped,

2 answers

Line 2 is your problem, you did not define it correctly. To find a specific tool in Backpack like PSTL you must define it like this

local Player = game.Players.LocalPlayer
local Backpack = Player:WaitForChild("Backpack")
local gun = Backpack:WaitForChild("PSTL")

gun.Equipped:connect(function(mouse)
Player.PlayerGui.ScreenGui.Frame.TextLabel.Text = "PSTL"
end)

1 comment

0

It would be much more stable if you had this script in the gun and redefined "gun" as local gun = script.Parent, But that is for you to decide the way you find easiest.

Make sure the tool has a handle otherwise the equipped event won't fire, also on line 2 of your code, it should be

local gun = Player.Backpack:WaitForChild("PSTL") since you already have Player referenced as the local player

Complete Code

repeat wait() until game:GetService'Players'.LocalPlayer -- Just to be safe
local Player = game.Players.LocalPlayer
local gun = Player:WaitForChild'Backpack':WaitForChild'PSTL' 

gun.Equipped:connect(function(mouse) -- Make sure your tool has a handle so this event fires.
	Player:WaitForChild'PlayerGui'.ScreenGui.Frame.TextLabel.Text = "PSTL'
end)


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