-
What do you want to achieve?
When using this model, I wanted to create/use my own NPCs for the enemies. Once I got the custom sword to work, I decided to then work on using my NPCs instead of the ones from the model. However, the custom NPC doesn’t register with the quest stats while the one from the model does.
It’s kind of hard to explain with the limited knowledge I have, but I’ll insert a video to show what the problem is.
-
What is the issue?
As you can see, the quest stats don’t change when I kill the Sphere, only the Bandit.
EDIT: Video won’t upload, let me try to leave it in a comment or something.
EDIT2: Vimeo LINK
-
What solutions have you tried so far?
There are similar tutorials on Youtube so I’ve tried to follow them but I can’t figure out what the problem is. I’ve tried changing “Figure” to “Enemy” in the Sphere’s scripts; however, that still doesn’t fix the problem either.
I will attach all of the scripts in the Sphere as well as the Bandit below, perhaps that’s where the problem resides?
Sphere Scripts
Attack Script:
wait(1.5)
local sp = script.Parent
local Enemy = sp:WaitForChild("Humanoid")
local Head = sp:WaitForChild("Head")
local UpperTorso = sp:WaitForChild("UpperTorso")
local Animation = script:WaitForChild("AttackAnim")
local Animation1 = script:WaitForChild("AttackAnim1")
local Hit1 = Instance.new("Sound",UpperTorso)
Hit1.Volume = 1
Hit1.SoundId = " "
Hit1.Pitch = 0.15
local AttackEnabled = true
function wait(TimeToWait)
if TimeToWait ~= nil then
local TotalTime = 0
TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
while TotalTime < TimeToWait do
TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
end
else
game:GetService("RunService").Heartbeat:wait()
end
end
function DamageTag(parent,damage)
local DmgTag = script.DamageTag:clone()
DmgTag.Attack.Value = damage
DmgTag.Check.Value = game.Players.LocalPlayer
DmgTag.Disabled = false
DmgTag.Parent = parent
end
local Anim = Enemy:LoadAnimation(Animation)
local Anim1 = Enemy:LoadAnimation(Animation1)
local number = 1
function Hit(hit)
if hit.Parent ~= nil then
if hit.Parent:FindFirstChild("Humanoid") ~= nil and hit.Parent:FindFirstChild("Humanoid"):IsA("Humanoid") and AttackEnabled == true and TargetHum ~= Enemy then
local TargetHum = hit.Parent:FindFirstChild("Humanoid")
if not hit.Parent:FindFirstChild("NPC") then
AttackEnabled = false
delay(1,function() AttackEnabled = true end)
if Anim and number == 1 then Anim:Play() number = 2 end
if Anim and number == 2 then Anim1:Play() number = 1 end
DamageTag(TargetHum.Parent,5)
Hit1:Play()
end
end
end
end
for _, Child in pairs(script.Parent:GetChildren()) do
if Child:IsA("Part") or Child:IsA("WedgePart") or Child:IsA("CornerWedgePart") then
Child.Touched:connect(Hit)
end
end
DamageTag:
wait()
Humanoid = script.Parent:FindFirstChild("Humanoid")
if Humanoid ~= nil then
while Humanoid:findFirstChild("Check") do
Humanoid.Check:Destroy()
end
tag = script.Check:clone()
tag.Parent = Humanoid
game.Debris:AddItem(tag,5)
Humanoid:TakeDamage(script.Damage.Value)
end
script:remove()
Reward:
local Enemy = script.Parent.Humanoid
function KillForXp()
local tag = Enemy:findFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local Data = tag.Value:findFirstChild("Data")
local leader = tag.Value:FindFirstChild("Quest")
if leader.Num.Value == script.Parent.Data.Num.Value then
if leader ~= nil then
leader.Kills.Value = leader.Kills.Value + 1
end
end
if Data ~= nil then
Data.Beli.Value = Data.Beli.Value + 100
Data.Exp.Value = Data.Exp.Value + 100
wait(0.01)
script:Destroy()
end
end
end
end
Enemy.Died:connect(KillForXp)
Script: (removes the parts after it dies)
local Humanoid = script.Parent:WaitForChild("Humanoid")
Humanoid.Changed:Connect(function()
if Humanoid.Health <= 0 then
script.Parent:Destroy()
end
end)
Bandit Scripts
Attack Script:
wait(1.5)
local sp = script.Parent
local Enemy = sp:WaitForChild("Humanoid")
local Head = sp:WaitForChild("Head")
local UpperTorso = sp:WaitForChild("UpperTorso")
local Animation = script:WaitForChild("AttackAnim")
local Animation1 = script:WaitForChild("AttackAnim1")
local Hit1 = Instance.new("Sound",UpperTorso)
Hit1.Volume = 1
Hit1.SoundId = " "
Hit1.Pitch = 0.15
local AttackEnabled = true
function wait(TimeToWait)
if TimeToWait ~= nil then
local TotalTime = 0
TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
while TotalTime < TimeToWait do
TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
end
else
game:GetService("RunService").Heartbeat:wait()
end
end
function DamageTag(parent,damage)
local DmgTag = script.DamageTag:clone()
DmgTag.Attack.Value = damage
DmgTag.Check.Value = game.Players.LocalPlayer
DmgTag.Disabled = false
DmgTag.Parent = parent
end
local Anim = Enemy:LoadAnimation(Animation)
local Anim1 = Enemy:LoadAnimation(Animation1)
local number = 1
function Hit(hit)
if hit.Parent ~= nil then
if hit.Parent:FindFirstChild("Humanoid") ~= nil and hit.Parent:FindFirstChild("Humanoid"):IsA("Humanoid") and AttackEnabled == true and TargetHum ~= Enemy then
local TargetHum = hit.Parent:FindFirstChild("Humanoid")
if not hit.Parent:FindFirstChild("NPC") then
AttackEnabled = false
delay(1,function() AttackEnabled = true end)
if Anim and number == 1 then Anim:Play() number = 2 end
if Anim and number == 2 then Anim1:Play() number = 1 end
DamageTag(TargetHum.Parent,5)
Hit1:Play()
end
end
end
end
for _, Child in pairs(script.Parent:GetChildren()) do
if Child:IsA("Part") or Child:IsA("WedgePart") or Child:IsA("CornerWedgePart") then
Child.Touched:connect(Hit)
end
end
DamageTag:
wait()
Humanoid = script.Parent:FindFirstChild("Humanoid")
if Humanoid ~= nil then
while Humanoid:findFirstChild("Check") do
Humanoid.Check:Destroy()
end
tag = script.Check:clone()
tag.Parent = Humanoid
game.Debris:AddItem(tag,5)
Humanoid:TakeDamage(script.Damage.Value)
end
script:remove()
Follow: (I’m not using this script in Sphere since I’ve created my own)
MY OWN (IN SPHERE)
BANDIT LAYOUT
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 30
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("HumanoidRootPart")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - script.PartSu.Position).Magnitude < dist then
torso = temp
dist = (temp.Position - script.PartSu.Position).Magnitude
end
end
end
end
return torso
end
while true do
wait(math.random(1,2))
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target ~= nil and not target.Parent:findFirstChild("NPC") then
script.Parent.Humanoid:MoveTo(target.Position, target)
else
script.Parent.Humanoid:MoveTo(script.PartSu.Position, script.PartSu)
end
end
Respawn: (also not using this script in Sphere)
Dummy = script.Parent:Clone()
Enemy = script.Parent:WaitForChild("Humanoid")
Hum = script.Parent
Enemy.Died:connect(function()
wait(4)
Dummy:Clone().Parent = script.Parent.Parent
script.Parent:Destroy()
end)
Reward:
local Enemy = script.Parent.Humanoid
function KillForXp()
local tag = Enemy:findFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local Data = tag.Value:findFirstChild("Data")
local leader = tag.Value:FindFirstChild("Quest")
if leader.Num.Value == script.Parent.Data.Num.Value then
if leader ~= nil then
leader.Kills.Value = leader.Kills.Value + 1
end
end
if Data ~= nil then
Data.Beli.Value = Data.Beli.Value + 100
Data.Exp.Value = Data.Exp.Value + 100
wait(0.01)
script:Destroy()
end
end
end
end
Enemy.Died:connect(KillForXp)
Sorry for the many scripts! I hope it was useful information. However, I’ll also include a model with the model and my NPC for testing purposes.
Thanks