Hello all! I am creating an NPC Respawn script that calls the ReplicatedStorage service of ROBLOX. It then is supposed to use the :Clone() function from ReplicatedStorage and place it according to the position of a Part in the workspace!
The name of the part is "ElfSwordsmanSpawn", and it seems to function great the first time. After it respawns the NPC once, it breaks. Is there a way to fix this code? Or is there something wrong ?
Here is my code, this is a Server Script in the ServerScriptService
local spawnLocation = game.Workspace:FindFirstChild("ElfSwordsmanSpawn") --Where you want the NPC to spawn
while true do
wait(1)
if not game.Workspace:FindFirstChild("ElfSwordsman") then--Npc name here
local CloneNpc = game.ReplicatedStorage:WaitForChild("ElfSwordsman"):Clone()
CloneNpc.Parent = game.Workspace
CloneNpc.Position = Vector3.new(0.175, 14.275, -13.4)
end
end

2 comments
make usre ur deleting the npc. also, replicated storage disables scripts im pretty sure
if it's an NPC then it's gonna be a model so .Position won't work, if this is the case then that's the problem, it'll error and not run again. To fix this, use CloneNpc.HumanoidRootPart.Position = Vector3.new(0.175, 14,275, -13.4)