How to display a gui when equiping a tool

I have a script that kills the player when picking up a tool, I need gui to be displayed when picking up an item.
This is my script (This is the local script)

local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

Tool.Equipped:Connect(function()
	Character.Humanoid:TakeDamage(100) 
wait(1)
	game.StarterGui.ScreenGui.Frame.Visible = true
	wait(5)
	game.StarterGui.ScreenGui.Frame.Visible = false
end)
1 Like

Everything is cloned from StarterGui into the player’s PlayerGui once the player joins the game (you’ll need to access their PlayerGui.)

2 Likes

You shouldn’t use game.StarterGui as the UIs in StarterGui are automatically cloned in to each player, you need to reference the PlayerGui in the player to actually change the visibility

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local gui = Player:WaitForChild("PlayerGui")

Tool.Equipped:Connect(function()
	Character.Humanoid:TakeDamage(100) 
	wait(1)
	gui.ScreenGui.Frame.Visible = true
	wait(5)
	gui.ScreenGui.Frame.Visible = false
end)

Edit: Included why it’s not good to use game.StarterGui

2 Likes

Since the tool is being cloned to the olayer’s backpack form starterpack, you’ll have to use your Player variable and do “Players:WaitForChild(“PlayerGui”)”

Player’s do not load instant in the game, so we have to wait for the player and the stuff inside the player to load.

Make sure to place the ui in StarterGui.

2 Likes

You should at least say why, no one will learn from what you just said.
“You shouldn’t use game.StarterGui” is not a valid point.