Frame wont open when equiped tool

So I wanted a frame to open, whenever I equipped my tool. I made a local script in my screengui :

tool = game.ReplicatedStorage.GamepassTools.LightStick
handle = tool:WaitForChild("Handle")
tool.Equipped:Connect(function()
    script.Parent.Frame.Visible = true
end)

When I equip my tool the frame does not turn visible. How do I fix this?

That’s because it gets the tool from rep storage. Not the tool in the player’s backpack. Because when the tool is equipped it’s in the player’s backpack.
Here’s a simple script that fixes it

local Player = game.Players.LocalPlayer
local BackPack = Player.Backpack
local Tool = BackPack:WaitForChild("LightStick")
Tool.Equipped:Connect(function()
	script.Parent.Frame.Visible = true
end)
1 Like
repeat wait() until game.players.LocalPlayer.Character
local tool = game.players.LocalPlayer.Backpack.LightStick
1 Like

Repeating the same code over and over again with a wait() isn’t really efficient. While you can use a simple :waitforchild()

1 Like

also .players is supposed to be capital. Not lowercase.

1 Like

I just wanted to try and empasize on waiting for the character to load.
In other to prevent an error.

1 Like

Yknow u can do this to get the character instead of repeating:

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

Just a tip.

1 Like

Thank you, but the studio always auto corrects me.
When it doesn’t, I spell it right, so, no worries.

2 Likes
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local backpack = player:WaitForChild("Backpack")
local lightStick = backpack:WaitForChild("LightStick")

lightStick.Equipped:Connect(function()
	script.Parent.Frame.Visible = true
end)

The handle of a tool doesn’t have the Equipped/Unequipped events, the tool instance itself does.