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:
- You are not spelling it correctly, or accessing the wrong directory.
- The directory does not exist (TalkingNPC isn't in PlayerGui.Players)
- 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
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
3 comments
why did you paste it as normal text?
May I ask, where is this script located in your game?
You have to do :WaitForChild(TalkingNPC)