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

it keeps saying TalkingNPC is not a valid member of PlayerGui.Players ?

local player = game.Players.LocalPlayer local CreateDialogueEvent = game.ReplicatedStorage.CreateDialogueEvent local DialogueFrame = player.PlayerGui.TalkingNPC.Frame

local function playSound(sound_id) local sound = Instance.new("Sound",game.ReplicatedStorage) sound.SoundId = sound_id sound.Volume = .1 sound.PlayOnRemove = true sound:Destroy() end

local function textAnimate(content) for i = 1,string.len(content) do DialogueFrame.Text.Text = string.sub(content,1,i) playSound("rbxassetid://179235828") if string.sub(content,i,i) == "!" or string.sub(content,i,i) == "." or string.sub(content,i,i) == "?" then wait(1) elseif string.sub(content,i,i) == "," then wait(.5) else wait(.05) end end

3 comments

0

why did you paste it as normal text?

0

May I ask, where is this script located in your game?

0

You have to do :WaitForChild(TalkingNPC)

1 answer

local player = game.Players.LocalPlayer
local CreateDialogueEvent = game.ReplicatedStorage.CreateDialogueEvent
local DialogueFrame = player.PlayerGui.TalkingNPC.Frame

local function playSound(sound_id)
    local sound = Instance.new("Sound", game.ReplicatedStorage)
    sound.SoundId = sound_id
    sound.Volume = .1
    sound.PlayOnRemove = true
    sound:Destroy()
end

local function textAnimate(content)
    for i = 1, string.len(content) do
        DialogueFrame.Text.Text = string.sub(content, 1, i)
        playSound("rbxassetid://179235828")
        if string.sub(content, i, i) == "!" or string.sub(content, i, i) == "." or string.sub(content, i, i) == "?" then
            wait(1)
        elseif string.sub(content, i, i) == "," then
            wait(.5)
        else
            wait(.05)
        end
    end
end

I don't know where you put this, but it appears this is happening because this directory in your game does not exist. There are three reasons this can be the case:

  1. You are not spelling it correctly, or accessing the wrong directory.
  2. The directory does not exist (TalkingNPC isn't in PlayerGui.Players)
  3. TalkingNPC hasn't loaded on the client yet, or you are creating it with a script of your own which is running after this one (causing TalkingNPC to be nonexistent at that point in time)

Double check for the first two. If those aren't the case, it is #3. In that case you can use :WaitForChild(). Here is how you do so:

local player = game.Players.LocalPlayer
local CreateDialogueEvent = game.ReplicatedStorage.CreateDialogueEvent
local DialogueFrame = player.PlayerGui:WaitForChild("TalkingNPC").Frame --Right here is where we do it. Btw WaitForChild is a good practice since many things are often not loaded in (or you can use your own waitforchild if you decide to script your own function for it)

local function playSound(sound_id)
    local sound = Instance.new("Sound", game.ReplicatedStorage)
    sound.SoundId = sound_id
    sound.Volume = .1
    sound.PlayOnRemove = true
    sound:Destroy()
end

local function textAnimate(content)
    for i = 1, string.len(content) do
        DialogueFrame.Text.Text = string.sub(content, 1, i)
        playSound("rbxassetid://179235828")
        if string.sub(content, i, i) == "!" or string.sub(content, i, i) == "." or string.sub(content, i, i) == "?" then
            wait(1)
        elseif string.sub(content, i, i) == "," then
            wait(.5)
        else
            wait(.05)
        end
    end
end

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