- What do you want to achieve? What is the issue?
My script spawns an NPC from a folder with various characters into a Workspace folder. Then, it should make the NPC state “hello”, but the NPC doesn’t actually state anything.
This is the script that I made for this:
local replicated = game:GetService("ReplicatedStorage")
local ChatService = game:GetService("Chat")
local NPCdictionary = game.Workspace.NPC -- where NPCS are cloned to
local NPCcharacters = replicated:WaitForChild("NPCchars") -- folder where characters are stored
local function spawnNPC()
local selection = NPCcharacters:GetChildren()
local randomNPC = selection[math.random(1, #selection)]
local npc = randomNPC:Clone()
npc.Parent = NPCdictionary
npc.HumanoidRootPart.Anchored = false
local root = npc:WaitForChild("HumanoidRootPart")
root.CFrame = NPCdictionary.Parent.NPCSpawn.TeleportPart.CFrame
return npc, root -- root is just the HumanoidPart for the next code
end
local Dummy, Root = spawnNPC()
ChatService:Chat(Dummy.Head, "hello")
This script is in ServerScriptService, and the NPC does get spawned correctly like how I want it to but I’m having trouble with making the last line actually work.