like the title said the bone animation won’t play correctly
function setUp()
local BodyVelocity = Instance.new("BodyVelocity", script.Parent.SpiderMesh)
BodyVelocity.Velocity = Vector3.new(0,0,0)
local BodyGyro = Instance.new("BodyGyro", script.Parent.SpiderMesh)
BodyGyro.MaxTorque = Vector3.new(400000, 400000, 400000)
return BodyVelocity, BodyGyro
end
wait(1)
local BV, BG = setUp()
function MoveTo(Target)
local S = 13
local D = (Target.Position - script.Parent.SpiderMesh.Position).Unit
local F = D * S
BV.Velocity = F
BG.CFrame = CFrame.new(script.Parent.SpiderMesh.Position, Target.Position)
end
function SetUpAnimationControl()
local AnimationControl = script.Parent:FindFirstDescendant("AnimationController")
if AnimationControl then
AnimationControl:Destroy()
end
local NewAnimationControl = Instance.new("AnimationController", script.Parent)
local NewAnimator = Instance.new("Animator", NewAnimationControl)
return NewAnimator
end
function CreateAnimTrack(Animation, loop)
local AnimationControl = script.Parent:FindFirstChild("AnimationController")
local Animator = nil
if not AnimationControl then
Animator = SetUpAnimationControl()
else
Animator = AnimationControl:FindFirstChild("Animator")
if not Animator then
Animator = SetUpAnimationControl()
end
end
local AnimTrack = AnimationControl:LoadAnimation(Animation)
AnimTrack.Looped = loop
return AnimTrack
end
function distanceCheck(Target, Distance)
if (Target.Position - script.Parent.SpiderMesh.Position).Magnitude <= Distance then
return true
else
return false
end
end
local Owner = script.Parent.Owner
local tween = game:GetService("TweenService")
local WalkAnimation = script.Parent:WaitForChild("SpiderWalk")
local AnimationTrack = CreateAnimTrack(WalkAnimation, true)
while true do
wait()
local Player = Owner.Value
if Player then
local Character = Player.Character or Player.CharacterAdded:Wait()
local HRP = Character.HumanoidRootPart
local DistanceCheck = distanceCheck(HRP, 10)
if DistanceCheck then
AnimationTrack:Stop()
local TweenTrack = tween:Create(BV, TweenInfo.new(0.5), {Velocity = Vector3.new(0,0,0)})
TweenTrack:Play()
local connect
connect = TweenTrack.Changed:Connect(function()
if not distanceCheck(HRP, 10) then
TweenTrack:Pause()
connect:Disconnect()
end
end)
else
AnimationTrack:Play()
MoveTo(HRP)
end
end
end