Hello! I am freaking out!! I am sitting 2h on this code rn but it wont work!
For your information:
I have a NPC that fights against me. When i kill him i want him to give me a kill and then respawns. But he wont respawn! I tried almost everything. Please help
Script:
killed = false
player = game:GetService("Players").PlayerAdded:Wait()
local Kills = player:WaitForChild("leaderstats"):WaitForChild("Kills")
local Copy = script.Parent:Clone()
local NPC = script.Parent
local spawnpos = 1
local Humanoid
for i,v in pairs(NPC:GetChildren()) do
if v:IsA('Humanoid') then
Humanoid = v
end
end
while wait() do
Humanoid.Died:Connect(function()
if killed == false then
killed = true
Kills.Value = Kills.Value + 1
print("addedkill")
wait(5)
print("RESPAWNED")
local npc1 = script.Parent
local npc2 = npc1:Clone()
npc2.Parent=game.Workspace
npc2:makeJoints()
npc2:MoveTo(Vector3.new(123.805, 8.173, -321.671))
script.Parent:Destroy()
wait(10)
killed = false
end
end)
end