so basically, im trying to make a title sequence and when you step on the brick, the title of the game will appear (I have that done already). The thing I need help with is making it only stay on the screen for like 5 seconds then get destroyed never to be seen again (even after youve died and re-spawned).
This is the script I have so far:
local Part = script.Parent Part.Touched:connect(function(HIT) local H = HIT.Parent:FindFirstChild("Humanoid") if H then local Player = game.Players:GetPlayerFromCharacter(HIT.Parent) Player.PlayerGui.TitleSequence.Frame.Visible = true end end)
I have never used this before so sorry if i asked the question wrong or something
Information
Use :GetService() to retrieve the Players Service
Use :WaitForChild()
to make sure an instance exists before using it
Use a "debounce" so that the touched event doesn't run your code again before the cooldown (5 seconds) is done
I'd check the existence of the HIT, its parent, and the player rather than the Humanoid so that you can be sure that a player and not some npc touched the part.
Use :Destroy()
to remove an instance forever
Revised Server Script
local Part = script.Parent local debounce = false Part.Touched:connect(function(HIT) if HIT and HIT.Parent and game:GetService("Players"):GetPlayerFromCharacter(HIT.Parent) then local Player = game:GetService("Players"):GetPlayerFromCharacter(HIT.Parent) local gui = Player:WaitForChild("PlayerGui"):FindFirstChild("TitleSequence") if gui and debounce == false then debounce = true gui:WaitForChild("Frame").Visible = true wait(5) gui:Destroy() debounce = false end end end)
IMPORTANT: make sure that the "TitleSequence"'s ResetOnSpawn
property is set to false
so that a player's death will not reinstate the ScreenGui
Well first off, your script doesn’t even have a line of code that says it’ll be gone after 5 seconds, so try this.
local Part = script.Parent Part.Touched:connect(function(HIT) local H = HIT.Parent:FindFirstChild("Humanoid") if H then local Player = game.Players:GetPlayerFromCharacter(HIT.Parent) Player.PlayerGui.TitleSequence.Frame.Visible = true end wait(5) Player:WaitForChild(“PlayerGui”).TitleSequence.Frame:Destroy() end) end)