Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

How do you make NPC dialog from ScreenGuis?

Asked by 3 years ago

I want it so when you click on the NPC that the dialog appears. It shows that I can click on it but the dialog isn't popping up. This is the script that I am using.

NPC = script.Parent
Screen = game.StarterGui.FirstTextGui
Frame = Screen.FirstTextBox
Text = Frame.FirstText
Button = Text.NextButton
Talk = false

function onClicked()
    if Talk == false then
        Screen.Enabled = true
        Frame.Visible = true
        Text.Visible = true
        Button.Visible = true
        Talk = true
    elseif Talk == true then
        Screen.Enabled = false
        Frame.Visible = false
        Text.Visible = false
        Button.Visible = false
        Talk = false
    end
end

NPC.ClickDetector.MouseClicked:connect(onClicked)

It doesn't seem to work so please try to help me as much as possible since I am very new at Lua.

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

this is the first question I've ever answered I've tested it, it works :) using the StarterGui is not a good way to store your information or gui idk you should maybe store it somewhere like inside of the ReplicatedStorage or simply just inside the script

quick thing yu don't need all that Visible stuff if so throw it into one frame and only visible that one

your error was that in the startergui it enables but that doesn't show to anyone if it was to work it would throw it into everyone screen so coding has to know where to put it im probably really bad at explaining lol

wait(0.25)
local NPC = script.Parent
local Screen = script:WaitForChild('FirstTextGui')
local Talk = false

function onClicked(player) -- the player which clicked
local startergui = player:WaitForChild('PlayerGui') -- the players gui shown only on the for them
local screen = Screen:Clone() -- clone it
    if Talk == false then
        screen.Parent = startergui -- now paste it into the players gui
        Talk = true
    elseif Talk == true then
        if startergui:FindFirstChild(Screen.Name) then -- if found the gui
        startergui:FindFirstChild(Screen.Name):Destroy() -- kill it
        end
        Talk = false
    end
end

NPC.ClickDetector.MouseClick:connect(onClicked)

if it doesn't work uhh your doing something wrong

hopefully it works click the answer button :D cuz I need to answer one question atleast

0
This is fantastic! I had to tinker it a little bit, but it still worked fine! marioblast1244 113 — 3y
0
:D rareheaddress 74 — 3y
Ad

Answer this question