Change text and GUI transparency script not working

I’m trying to make a custom GUI dialogue system where there is one ScreenGui for every NPC. This is my script:

local clickdetector = game.Workspace.npc1.Head.ClickDetector
local dialogue = game.StarterGui.DialogueGui1
local npctext = game.StarterGui.DialogueGui1.MainFrame.PromptImage

dialogue.Transparency = 1

clickdetector.MouseClick:Connect(function()
    wait(0.2)
    dialogue.Transparency = 0.9
    dialogue.Transparency = 0.7
    dialogue.Transparency = 0.5
    dialogue.Transparency = 0.3
    dialogue.Transparency = 0
    wait(0.1)
    npctext.PromptText.Text = ("Hello there!")
    wait(5)
    dialogue.Transparency = 1
end)

However, when I test it, the ScreenGui’s transparency doesn’t change (it stays 100% visible even before I click the NPC) and the ScreenGui’s dialogue text (npctext.PrompText) doesn’t make the text box show text as well. What am I doing wrong, and how can I fix it?

StarterGui holds your GUI object information, when a player joins, your DialogueGui1 is automatically copied into game.Players.scoobisthebanana.PlayerGui. I believe there’s a boolean value on the screengui itself, so you could disable this behavior if you wanted to.

game.StarterGui.DialogueGui1 will only be referencing and changing transparency for the frame that is in StarterGui, which won’t be reflected on the copied gui inside of PlayerGui.
`

clickdetector.MouseClick:Connect(function(playerClicked)
    local playerGui = playerClicked.PlayerGui
    local dialogue = playerGui:FindFirstChild("DialogueGui1")
    local npctext = playerGui:FindFirstChild("PromptImage", true)
    wait(0.2)
    dialogue.Transparency = 0.9
    dialogue.Transparency = 0.7
    dialogue.Transparency = 0.5
    dialogue.Transparency = 0.3
    dialogue.Transparency = 0
    wait(0.1)
    npctext.PromptText.Text = ("Hello there!")
    wait(5)
    dialogue.Transparency = 1
end)
1 Like