Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How To Open A GUI With A ClickDetector?

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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!

0
it did work djcraft1237 4 — 3y
0
It will be helpful if you mark it as the answer BestCreativeBoy 1395 — 3y
0
new at scripting helpers. sorry djcraft1237 4 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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)

Answer this question