Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How To Open A GUI With A ClickDetector?

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

2 answers

✓ Accepted answer

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!

3 comments

0

it did work

0

It will be helpful if you mark it as the answer

0

new at scripting helpers. sorry

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.