-
What do you want to achieve? Keep it simple and clear!
I am trying to make a barbarian attack when a player or hostile npc is within it’s vicinity. -
What is the issue? Include screenshots / videos if possible!
The npc won’t change his animation nor go to the player/hostile npc. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried printing to debug, but as far as I can see it should be working.
My Script;
local NPC = script.Parent.Humanoid
local WayPoints = game.Workspace.BWP:GetChildren()
local Agro = false
local function Walk()
local RandomWayPoint = math.random(1, #WayPoints)
local ChosenWayPoint = WayPoints[RandomWayPoint]
NPC:MoveTo(ChosenWayPoint.Position)
NPC.MoveToFinished:Wait(2)
end
game.Workspace.Village.Agro.Touched:Connect(function(hit)
print(hit.Name)
if not hit.Parent.Name == "Barbarian" or not hit.Parent.Name == "BarbarianSoldier" and hit.Parent:FindFirstChild("Humanoid") then
Agro = true
NPC:MoveTo(hit.Position)
end
end)
game.Workspace.Village.Agro.TouchEnded:Connect(function(hit)
print(hit.Name)
if not hit.Parent.Name == "Barbarian" or not hit.Parent.Name == "BarbarianSoldier" and hit.Parent:FindFirstChild("Humanoid") then
Agro = false
end
end)
while Agro == false do
wait(2)
Walk()
end
My Animation Script
local AnimTrack = script.Parent.Humanoid.Animator:LoadAnimation(script.Animation)
local AnimTrack2 = script.Parent.Humanoid.Animator:LoadAnimation(script.Animation2)
local AnimTrack3 = script.Parent.Humanoid.Animator:LoadAnimation(script.Animation3)
--Walk Anim
script.Parent.Humanoid.Running:Connect(function(speed)
if speed > 0 and not AnimTrack.IsPlaying then
AnimTrack:Play()
elseif speed == 0 and AnimTrack.IsPlaying then
AnimTrack:Stop()
end
end)
--Shield Up Anim
game.Workspace.Village.Agro.Touched:Connect(function(hit)
if not hit.Parent.Name == "Barbarian" or not hit.Parent.Name == "BarbarianSoldier" and hit.Parent:FindFirstChild("Humanoid") then
if not AnimTrack2.IsPlaying then
AnimTrack2:Play()
end
end
end)
game.Workspace.Village.StopAgro.Touched:Connect(function(hit)
if not hit.Parent.Name == "Barbarian" or not hit.Parent.Name == "BarbarianSoldier" and hit.Parent:FindFirstChild("Humanoid") then
if AnimTrack2.IsPlaying then
AnimTrack2:Stop()
end
end
end)
--Swing Anim
local Cooldown = 1
local debounce = false
script.Parent.SwingDist.Touched:Connect(function(hit)
if not hit.Parent.Name == "Barbarian" or not hit.Parent.Name == "BarbarianSoldier" and hit.Parent:FindFirstChild("Humanoid") then
if not AnimTrack3.IsPlaying and not debounce then
debounce = true
AnimTrack3:Play()
elseif not AnimTrack3.IsPlaying and debounce then
wait(Cooldown)
debounce = false
end
end
end)
The npc is a custom rig.