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

Equipping a tool?

Asked by 8 years ago
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

Log in to vote
1
Answered by 8 years ago

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)
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. SurvivalAptissimum 25 — 8y
Ad
Log in to vote
1
Answered by
4Bros 550 Moderation Voter
8 years ago

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)


Answer this question