I have a script that i want to use the animation events for the animations played. However Animation events don’t work server side apparently and animations are better played client side. So i was wondering if anyone knows a good way to convert the animations played on this script to a local script
i also tried using a remote event to recreate the Heartbeat on a local script but that gave me a “remote function invocation queue exhausted” error. Thanks
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Model = script.Parent.Parent
local humanoid = script.Parent
local root = humanoid.Parent.PrimaryPart
root:SetNetworkOwner(nil)
local TargetDistance = script.Parent.Parent:GetAttribute("TargetDistance")
local StopDistance = script.Parent.Parent:GetAttribute("StopDistance")
local Damage = script.Parent.Parent:GetAttribute("Damage")
local AttackDistance = script.Parent.Parent:GetAttribute("AttackDistance")
local AttackCooldown = script.Parent.Parent:GetAttribute("AttackCooldown")
local LastAttack = tick()
local Animator = humanoid:WaitForChild("Animator")
local IdleAnimation = script:WaitForChild("Idle")
local WalkingAnimation = script:WaitForChild("Walk")
local AttackAnimation = script:WaitForChild("Attack")
local IdleTrack = Animator:LoadAnimation(IdleAnimation)
local WalkingTrack = Animator:LoadAnimation(WalkingAnimation)
local AttackTrack = Animator:LoadAnimation(AttackAnimation)
if WalkingTrack.IsPlaying or AttackTrack.IsPlaying then
IdleTrack:Stop()
else
IdleTrack:Play()
end
function FindNearestPlayer()
local playerList = Players:GetPlayers()
local nearestPlayer = nil
local distance = nil
local direction = nil
for _, player in pairs(playerList) do
local character = player.Character
local distanceVector = (player.Character.HumanoidRootPart.Position - root.Position)
if character then
if not nearestPlayer then
nearestPlayer = player
distance = distanceVector.Magnitude
direction = distanceVector.Unit
elseif distanceVector.Magnitude < distance then
nearestPlayer = player
distance = distanceVector.Magnitude
direction = distanceVector.Unit
end
end
end
return nearestPlayer, distance, direction
end
RunService.Heartbeat:Connect(function()
local nearestPlayer, distance, direction = FindNearestPlayer()
if nearestPlayer then
if distance <= TargetDistance and distance >= StopDistance then
--Runs when walking
if not WalkingTrack.IsPlaying then
WalkingTrack:Play()
end
humanoid:Move(direction)
else
--Runs when standing still
if WalkingTrack.IsPlaying then
WalkingTrack:Stop()
end
humanoid:Move(Vector3.new())
end
if distance <= AttackDistance and tick() - LastAttack >= AttackCooldown and Model:GetAttribute("Stunned") == false then
--runs when attacking
AttackTrack:Play()
LastAttack = tick()
end
end
end)
-- what the walkspeed and jump height will revert to
local BaseWalkSpeed = 12
local BaseJumpHeight = 50
coroutine.resume(coroutine.create(function()
while true do
wait()
if script.Parent.Parent:GetAttribute("Stunned") == true then
script.Parent.Parent:FindFirstChild("Humanoid").WalkSpeed = 0
script.Parent.Parent:FindFirstChild("Humanoid").JumpHeight = 0
else
script.Parent.Parent:FindFirstChild("Humanoid").WalkSpeed = BaseWalkSpeed
script.Parent.Parent:FindFirstChild("Humanoid").JumpHeight = BaseJumpHeight
end
end
end))