NPC Spawning inside of specific room does not work

I want that, upon a proximity prompt be activated, the npc teleports to the room which has the name “Room(NumberValue)”, the number value goes up by 1 each time a proximity prompt is added as well. So it should teleport in each unique room. All rooms have the “NPCSpawn” part inside of them.

I am not sure what the issue here is, but it says it can’t index number from NPCSpawn in the Developer Console.

script:

local debounce = false


game:GetService("ProximityPromptService").PromptTriggered:Connect(function()
if not debounce then
	debounce = true
	wait(0.01)
	local NPCClone = game.ReplicatedStorage.NPC:Clone()
	NPCClone.Parent = game.Workspace.NPCs --folder
	NPCClone.Humanoid.RootPart.CFrame = game.Workspace["Room"]..game.ReplicatedStorage.RoomNo.Value.NPCSpawn.CFrame --This is the part that is bugged
		wait(35)
		debounce = false
		NPC:Destroy()
	end
end)

Anyone who can help would be a life saver!

1 Like

Hey there! I noticed you accidentally added a period after you typed Humanoid
previously

NPCClone.Humanoid.RootPart.CFrame = game.Workspace["Room"]..game.ReplicatedStorage.RoomNo.Value.NPCSpawn.CFrame --This is the part that is bugged

now

NPCClone.HumanoidRootPart.CFrame = game.Workspace["Room"..game.ReplicatedStorage.RoomNo.Value].NPCSpawn.CFrame

Just replace the one line I changed with the new one, and then try that.

2 Likes

Thanks, I thought you had to type it as [“Room”]…numvalue rather than [“Room”…numvalue].