I have a huge problem! when a rig walks towards the player, the walk animation triggers several times, I would just like it to walk towards the player by playing the animation once
--Part of code (module script)
humanoid.Running:Connect(function(speed: number)
if speed > 0 then
print("is running")
walkAnimation:Play()
else
walkAnimation:Stop()
end
end)
--part of code (script)
while true do
local magnitude = (humanoidRootPart.Position - model.HumanoidRootPart.Position).Magnitude
task.wait(0.3)
if magnitude <= 40 then
model.Humanoid:MoveTo((humanoidRootPart.CFrame * CFrame.new(0, 0, 5)).Position)
end
end
--Part of code (module script)
humanoid.Running:Connect(function(speed: number)
if speed > 0 then
print("is running")
if not walkAnimation.IsPlaying then
walkAnimation:Play()
end
else
walkAnimation:Stop()
end
end)
I may have the mistake that the rig will follow the player a point A → B well the problem is that it will be all the time and cause this kind of problem but to solve it I do not know too much
--part of module
humanoid.Running:Connect(function(speed: number)
if speed > 0 then
if not walkAnimation.IsPlaying then
walkAnimation:Play()
end
elseif speed <= 0 then
walkAnimation:Stop()
end
end)
part of script
local function onPlayerAdded(player: Player)
local model = newBoss:SetProperty()
local function onCharacterAdded(char: Model)
local humanoidRootPart = char:FindFirstChild("HumanoidRootPart"):: BasePart
while true do
task.wait(0.1)
local magnitude = (humanoidRootPart.Position - model.HumanoidRootPart.Position).Magnitude
model.Humanoid:MoveTo((humanoidRootPart.CFrame * CFrame.new(0, 0, 5)).Position)
end
end
player.CharacterAdded:Connect(onCharacterAdded)
end
humanoid.Running:Connect(function(speed: number)
if speed > 0 then
if not walkAnimation.IsPlaying then
print("animation played")
walkAnimation:Play()
end
elseif speed <= 0 then
print("Animation finish")
walkAnimation:Stop()
end
end)