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