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

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

Asked by 3 years ago

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

0
why did you paste it as normal text? Nozazxe 107 — 3y
0
May I ask, where is this script located in your game? RetroGalacticGamer 331 — 3y
0
You have to do :WaitForChild(TalkingNPC) shieldmr3 2 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
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

Ad

Answer this question