I Wanted To Make A Clickable NPC With ClickDetector. That ClickDetector Will Activate A GUI And After 5 Seconds The GUI Will Disappear, I Tried Doing
script.Parent.MouseClick:Connect(function() Frame.Visible = true wait(5) Frame.Visible = false
I Put ClickDetector As The Child Of The Clickable NPC Script Is Under ClickDetector And ScreenGUI Is Under StarterGUI
Your code is little incomplete to provide with the support but it is managable. For now, I am going to create an assuming Frame variable which will be helpful.
script.Parent.MouseClick:Connect(function(player) -- Adding a parameter for the player clicking -- Creating Frame variable local PlayerGui = player:WaitForChild("PlayerGui") -- Gets the PlayerGui of the player, where all the contents of StarterGui are copied local Frame = PlayerGui.ScreenGui.Frame -- It's assumable, change this to that of yours Frame.Visible = true wait(5) Frame.Visible = false end)
Lemme know if it helps!
I have my explanation in the code below:
script:FindFirstAncestorWhichIsA("ClickDetector").MouseClick:Connect(function(Player) --[[ ClickDetectors have a built-in player argument, you just have to supply it @ ":Connect(function(Player)" ]] local PlayerGui = Player:FindFirstChildWhichIsA("PlayerGui") local Frame = nil -- Replace nil with the path to your GUI, ex: PlayerGui.ScreenGui.Frame Frame.Visible = true wait(5) Frame.Visible = false end)