Not a valid member of PlayerGui

I have a problem with my NPC interactions script, it’s in ScreenGUI, it keeps giving me an error saying the specific GUI is not a valid member while it is in Studio and Even in game (checked with explorer)

Error:

This is my code

--Click detectors  
local shopguy = workspace.shopguy.ClickDetector
local specialshop = workspace.SpecialStands.ClickDetector
local bank = workspace.Banker.ClickDetector
local masteryskins = workspace.MasteryStands.ClickDetector
local theskinshop = workspace.SkinShop.ClickDetector
local joemama = workspace.JoeMamaRock.ClickDetector
local bluefish = workspace.fish.ClickDetector
local angelo = workspace.AngeloStone.ClickDetector
--NPC BAR STUFF
local nike = workspace.Nike.ClickDetector
local errors = workspace.ErrorsNPC.ClickDetector

--Variables
		
--Other stuff

local gui = script.Parent["DialogueGui"]
local NPCname = gui.NPCName.Text
local dialogue = gui.Dialogue.Text
local image = gui.Picture.ShopOwner
local image2 = gui.Picture.Jotaro
local image3 = gui.Picture.Banker
local image4 = gui.Picture.EventShopOwner
local image5 = gui.Picture.SpecialShop
local dialoguedb = false
image.Visible = false

Player = game:GetService("Players")["LocalPlayer"]
local playername = Player.Name
local char = Player.Character
local hum = char:WaitForChild("Humanoid")

--Events
local repstorage = game:GetService("ReplicatedStorage")
local zeppelievent = repstorage.ShopEvent

--Data Detection
local stand = Player:WaitForChild("Data")["Stand"]

--Functions

function closenormalshop()
local shopgui = script.Parent.SHOP1UI
local theshop = shopgui.Frame
theshop:TweenPosition(UDim2.new(-0.3, 0, 0.118, 0), 'Out', 'Quart', 1)
end

shopguy.MouseClick:Connect(function()
	if not dialoguedb then
		dialoguedb = true
		gui.Enabled = true
local shopgui = script.Parent.SHOP1UI
local theshop = shopgui.Frame
		theshop:TweenPosition(UDim2.new(-0.3, 0, 0.118, 0), 'Out', 'Quart', 1)
		NPCname.Text = "Shop Owner"
		theshop.Position = UDim2.new(-0.3, 0, 0.118, 0)
		local line1 = "Looking for something?"
		local voice = game.Workspace.SoundLibrary.Voice:Clone()
		voice.Parent = shopguy.Parent.Head
		voice.TimePosition = 0.2
		voice.SoundId = "rbxassetid://4301105173"
		voice.PlaybackSpeed = 1.25
		for i = 1, #line1 do
			dialogue.Text = string.sub(line1, 1, i)
			wait(0.05)
			voice:Play()
		end
		wait(1)
		gui.Enabled = false
		dialoguedb = false
        image.Visible = false
		voice:Destroy()
		shopgui.Enabled = true
		wait(0.15)
		theshop:TweenPosition(UDim2.new(0, 0, 0.118, 0), 'Out', 'Quart', 1)
	end
end)

bank.MouseClick:Connect(function()
	if not dialoguedb then
		dialoguedb = true
		gui.Enabled = true
local shopgui = script.Parent.Bank
local theshop = shopgui.Frame
		theshop:TweenPosition(UDim2.new(-0.3, 0, 0.118, 0), 'Out', 'Quart', 1)
		NPCname.Text = "The Bank"
		theshop.Position = UDim2.new(-0.3, 0, 0.118, 0)
		local line1 = "Cashing out today?"
		local voice = game.Workspace.SoundLibrary.Voice:Clone()
		voice.Parent = bank.Parent.Head
		voice.TimePosition = 0.2
		voice.SoundId = "rbxassetid://4301105173"
		voice.PlaybackSpeed = 1.25
		for i = 1, #line1 do
			dialogue.Text = string.sub(line1, 1, i)
			wait(0.05)
			voice:Play()
		end
		wait(1)
		gui.Enabled = false
		dialoguedb = false
        image.Visible = false
		voice:Destroy()
		shopgui.Enabled = true
		wait(0.15)
		theshop:TweenPosition(UDim2.new(0, 0, 0.118, 0), 'Out', 'Quart', 1)
	end
end)


specialshop.MouseClick:Connect(function()
	if not dialoguedb then
		dialoguedb = true
		gui.Enabled = true
local shopgui = script.Parent.LimitedEditionShop
local theshop = shopgui.Frame
		theshop:TweenPosition(UDim2.new(-0.3, 0, 0.118, 0), 'Out', 'Quart', 1)
		NPCname.Text = "Skin Shop"
		theshop.Position = UDim2.new(-0.3, 0, 0.118, 0)
		local line1 = "Limited Edition skins currently on sale:"
		local voice = game.Workspace.SoundLibrary.Voice:Clone()
		voice.Parent = specialshop.Parent["Stand Torso"]
		voice.TimePosition = 0.2
		voice.SoundId = "rbxassetid://4301105173"
		voice.PlaybackSpeed = 1.25
		for i = 1, #line1 do
			dialogue.Text = string.sub(line1, 1, i)
			wait(0.05)
			voice:Play()
		end
		wait(1)
		gui.Enabled = false
		dialoguedb = false
        image.Visible = false
		voice:Destroy()
		shopgui.Enabled = true
		wait(0.15)
		theshop:TweenPosition(UDim2.new(0, 0, 0.118, 0), 'Out', 'Quart', 1)
	end
end)

masteryskins.MouseClick:Connect(function()
	if not dialoguedb then
		dialoguedb = true
		gui.Enabled = true
local shopgui = script.Parent.MasteryShopGUI
local theshop = shopgui.Frame
		theshop:TweenPosition(UDim2.new(-0.3, 0, 0.118, 0), 'Out', 'Quart', 1)
		NPCname.Text = "Mastery Variants"
		theshop.Position = UDim2.new(-0.3, 0, 0.118, 0)
		local line1 = "Current mastery variants:"
		local voice = game.Workspace.SoundLibrary.Voice:Clone()
		voice.Parent = masteryskins.Parent["Stand Torso"]
		voice.TimePosition = 0.2
		voice.SoundId = "rbxassetid://4301105173"
		voice.PlaybackSpeed = 1.25
		for i = 1, #line1 do
			dialogue.Text = string.sub(line1, 1, i)
			wait(0.05)
			voice:Play()
		end
		wait(1)
		gui.Enabled = false
		dialoguedb = false
        image.Visible = false
		voice:Destroy()
		shopgui.Enabled = true
		wait(0.15)
		theshop:TweenPosition(UDim2.new(0, 0, 0.118, 0), 'Out', 'Quart', 1)
	end
end)

theskinshop.MouseClick:Connect(function()
	if not dialoguedb then
		dialoguedb = true
		gui.Enabled = true
local shopgui = script.Parent.SkinnoShop
local theshop = shopgui.Frame
		theshop:TweenPosition(UDim2.new(-1, 0, 0.132, 0), 'Out', 'Quart', 1)
		NPCname.Text = "Skin Shop"
		theshop.Position = UDim2.new(-1, 0, 0.132, 0)
		local line1 = "Skins for sale:"
		local voice = game.Workspace.SoundLibrary.Voice:Clone()
		voice.Parent = theskinshop.Parent["Head"]
		voice.TimePosition = 0.2
		voice.SoundId = "rbxassetid://4301105173"
		voice.PlaybackSpeed = 1.25
		for i = 1, #line1 do
			dialogue.Text = string.sub(line1, 1, i)
			wait(0.05)
			voice:Play()
		end
		wait(1)
		gui.Enabled = false
		dialoguedb = false
        image.Visible = false
		voice:Destroy()
		shopgui.Enabled = true
		wait(0.15)
		theshop:TweenPosition(UDim2.new(0.145, 0, 0.132, 0), 'Out', 'Quart', 1)
	end
end)

bluefish.MouseClick:Connect(function()
	if not dialoguedb then
		dialoguedb = true
		gui.Enabled = true
		NPCname.Text = "Blue Fish"
		local line1 = "Glub Glub Glub"
		local voice = game.Workspace.SoundLibrary.Voice:Clone()
		voice.Parent = bluefish.Parent
		voice.TimePosition = 0.2
		voice.SoundId = "rbxassetid://1847405409"
		voice.PlaybackSpeed = 1.25
		voice:Play()
		for i = 1, #line1 do
			dialogue.Text = string.sub(line1, 1, i)
			wait(0.05)
		end
		wait(1)
		gui.Enabled = false
		dialoguedb = false
        image.Visible = false
		voice:Destroy()
	end
end)

angelo.MouseClick:Connect(function()
	if not dialoguedb then
		dialoguedb = true
		gui.Enabled = true
		NPCname.Text = "You"
		local line1 = "Yo, Angelo. 🗿"
		local voice = game.Workspace.SoundLibrary.Voice:Clone()
		voice.Parent = angelo.Parent
		voice.TimePosition = 0.2
		voice.SoundId = "rbxassetid://4301105173"
		voice.PlaybackSpeed = 1.25
		voice:Play()
		for i = 1, #line1 do
			dialogue.Text = string.sub(line1, 1, i)
			wait(0.05)
			voice:Play()
		end
		wait(1.75)
		gui.Enabled = false
		dialoguedb = false
        image.Visible = false
		voice:Destroy()
	end
end)

--531.4, 200.1, 175.4
--Add
--906.9
--49
--11/2/19
--NUH
joemama.MouseClick:Connect(function()
	if not dialoguedb then
		dialoguedb = true
		gui.Enabled = true
		NPCname.Text = "Joe Mama Arrow"
		local line1 = "NULL"
		local voice = game.Workspace.SoundLibrary.Voice:Clone()
		voice.Parent = joemama.Parent["Rock"]
		voice.TimePosition = 0.2
		voice.SoundId = "rbxassetid://4301105173"
		voice.PlaybackSpeed = 1.25
		for i = 1, #line1 do
			dialogue.Text = string.sub(line1, 1, i)
			wait(0.05)
			voice:Play()
		end
		wait(4)
		gui.Enabled = false
		dialoguedb = false
        image.Visible = false
		voice:Destroy()
	end
end)

nike.MouseClick:Connect(function()
	if not dialoguedb then
		dialoguedb = true
		gui.Enabled = true
		NPCname.Text = "Nike156"
		local line1 = "Welcome! Hey, you heard about ChimpCon 2020 next month? Hopefully I can get myself a ticket, I wouldn't wanna leave Fallen, Ody and Steak by themselves..."
		local voice = game.Workspace.SoundLibrary.Voice:Clone()
		voice.Parent = nike.Parent
		voice.TimePosition = 0.2
		voice.SoundId = "rbxassetid://4301105173"
		voice.PlaybackSpeed = 1.25
		voice:Play()
		for i = 1, #line1 do
			dialogue.Text = string.sub(line1, 1, i)
			wait(0.05)
			voice:Play()
		end
		wait(1.5)
		gui.Enabled = false
		dialoguedb = false
        image.Visible = false
		voice:Destroy()
	end
end)

errors.MouseClick:Connect(function()
	if not dialoguedb then
		dialoguedb = true
		gui.Enabled = true
		NPCname.Text = "Errors"
		local line1 = "Hello."			
		local voice = game.Workspace.SoundLibrary.Voice:Clone()
		voice.Parent = errors.Parent
		voice.TimePosition = 0.2
		voice.SoundId = "rbxassetid://4301105173"
		voice.PlaybackSpeed = 1.25
		voice:Play()
		for i = 1, #line1 do
			dialogue.Text = string.sub(line1, 1, i)
			wait(0.05)
			voice:Play()
		end
		wait(1)
		gui.Enabled = false
		dialoguedb = false
        image.Visible = false
		voice:Destroy()
	end
end)

I also did try changing the “Script.Parent[“DialogueGui”]” to “Script.Parent.DialogueGui” but that still didnt fix it.
This is how it is in Studio

On the client you should always use parent:WaitForChild(). This will yield until the child is found. Your script is probably running before the GUI exists.

5 Likes

I see, I’m not that good at scripting, my friend who does most of the scripting but he’s busy and I needed to fix that script. That fixed it, thank you so much!

1 Like

You forgot to put most of the code into the code block so I did it for ya:

–\ Made BY: fyyytdtghgg (Roblox 2019)
–\ NPC Chat System Gui Usage, Tween, Camera Manipulation, Variable Switching

–// Services

local RunService = game:GetService(“RunService”)
local UIS = game:GetService(“UserInputService”)
local Players = game:GetService(“Players”)

–// Main Variable

local DetectedNPC = nil
local Detected = false
local Chatting = false
local Skip = false
local Exit = false

–// Player

local Player = Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera

local Gui = script.Parent
local Sounds = Gui.Sounds
local PromptLabel = Gui.PromptLabel
local LineLabel = Gui.LineLabel

–// Character

local Character = Player.Character or Player.CharacterAdded:Wait()
local CharHMR = Character:WaitForChild(“HumanoidRootPart”)

–// NPC

local NPCS = game.Workspace:WaitForChild(“NPCS”)

–// Functions

UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.Z then
if Chatting == true then
Exit = true
Sounds.Click:Play()
end
end
end)

UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.E then

	if Detected == true then
		local Lines = DetectedNPC:FindFirstChild("Lines")
		
		if Lines then
			Sounds.Click:Play()
			
			Chatting = true
			Detected = false
			
			LineLabel.Text = " "
			
			PromptLabel:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Linear",0.2)
			LineLabel:TweenPosition(UDim2.new(0, 0, 0.8, 0), "In", "Linear",0.2)
			
			wait(0.5)
			
			for i, Line in pairs(Lines:GetChildren()) do
				local Text = Line.Value
				
				for i = 1, #Text do
					LineLabel.Text = string.sub(Text, 1, i)
					Sounds.Talk:Play()
					if Skip == true then
						Skip = false
						LineLabel.Text = Text
						break
					end
					if Exit == true then
						break
					end
					wait(0.07)
				end
				if Exit == true then
					Exit = false
					break
				end
				repeat wait() until Skip == true or Exit == true
				Skip = false
			end
			
			Exit = false
			Skip = false
			
			PromptLabel:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Linear", 0.2)
			LineLabel:TweenPosition(UDim2.new(0, 0, 1.2, 0), "Out", "Linear", 0.2)
			
			wait(0.5)
			
			Chatting = false
			Detected = false
		end
	end
end
end)

–// Main Loop

RunService.RenderStepped:Connect(function()

if Detected == false and Chatting == false then
	for i, NPC in pairs(NPCS:GetChildren()) do
		local Humanoid = NPC:FindFirstChild("Humanoid")
		local HMR = NPC:FindFirstChild("HumanoidRootPart")
		
		if Humanoid and HMR then
			if (HMR.Position - CharHMR.Position).magnitude < 15 then
				Detected = true
				DetectedNPC = NPC
				PromptLabel:TweenSize(UDim2.new(0, 60, 0, 60), "In", "Linear", 0.2)
				print(DetectedNPC.Name)
			end
		end
		
		
	end
end

    if Detected == true and Chatting == false then
    local Humanoid = DetectedNPC:FindFirstChild("Humanoid")
    local HMR = DetectedNPC:FindFirstChild("HumanoidRootPart")
		
	if Humanoid and HMR then
		if (HMR.Position - CharHMR.Position).magnitude  > 15 then
			Detected = false
			DetectedNPC = nil
			PromptLabel:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Linear", 0.2)
			print("No Longer Detected NPC")
		else
			local WTSP = Camera:WorldToScreenPoint(HMR.Position)
			PromptLabel.Position = UDim2.new(0, WTSP.X, 0, WTSP.Y)
		end
	end
end

if Chatting == true then
	local Humanoid = DetectedNPC:FindFirstChild("Humanoid")
    local HMR = DetectedNPC:FindFirstChild("HumanoidRootPart")
		
	if Humanoid and HMR then
		Camera.CameraType = Enum.CameraType.Scriptable
		Camera.CFrame = Camera.CFrame:Lerp(HMR.CFrame * CFrame.new(-4, 4, -7) * CFrame.fromOrientation(math.rad(-20), math.rad(215), 0), 0.07)
	end
else
	Camera.CameraType = Enum.CameraType.Custom
end
end)
1 Like