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

NPC Respawn Script, Only Spawning once? Fix?

Asked by
BryanFehr 133
5 years ago

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
0
make usre ur deleting the npc. also, replicated storage disables scripts im pretty sure EmbeddedHorror 299 — 5y
0
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) despicablejack2005 83 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

A simple way to move a whole model is by adding a PrimaryPart to the model and then using :MoveTo() to teleport your model to any position. In character models, the PrimaryPart is usual assigned to the HumanoidRootPart. Also, place all the models that you want to clone in ServerStorage for safe keeping. Here's my code:

while wait(1) do
    if not game.Workspace:FindFirstChild("ElfSwordsman") then

        local CloneNpc = game:GetService('ServerStorage'):WaitForChild("ElfSwordsman"):Clone()
    local SpawnLocation = game.Workspace:FindFirstChild("ElfSwordsmanSpawn") 

        CloneNpc.Parent = game.Workspace
        CloneNpc:MoveTo(spawnLocation.Position)

    end
end
0
if its a character the humanoidrootpart should be the primary part Luka_Gaming07 534 — 5y
Ad

Answer this question