Why not do it just on the server, instead of doing it on the client. While true do always crashes thats why u always put a task.wait() function so it does not.
I don’t even understand why you even wanna run that code in the heartbeat, secondly you can just play the animation on the server.
Well i want to use Animation events but they don’t work server side for some reason
I’m confused.
-
Remote function invocation queue exhausted
only happens if the request has timed out for aRemoteFunction
, not aRemoteEvent
, by not hooking a listener. - Your code does not even show where it is firing the
RemoteEvent
. However, you can manually rate limit theRemoteEvent
itself. - You can play animations server-side - you’re probably doing it wrong.
The problem is not playing animations that works fine but i need to get animations events which dont work
This is my original code problem is i want to use the animation event in the AttackTrack to make some warnings appear and stuff. but using getAnimationEvents dont wark on server scripts according to the documentation
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))
Change the server script’s runcontext to client, that may help though im not so familiar with runcontext
Nvm dont do that its not going to help
I’ve been looking around the forum and asking questions and won’t this type of script need like module scripts or sm? I’m not really sure how to use them but they work as like. server and client side connection or something right?
Don’t worry about runcontexts they just expand where you can place your scripts, for example usually if you place a localscript into workspace it wont work but with runcontext it does.
As for the main issue, id recommend using a while task.wati(2) loop instead of using heartbeat and then firing the remote event when you need to.
when i do that the remote doesn’t even fire
sorry, but local script to play an animation on the npc??? that doesn’t even work??
am i missing something?
every forum post i see regarding animation always state that its better to play animations on a local script to reduce lag and allow use of GetAnimationEvents like Animations, server or client?. so i just assumed that was the best thing to do.
yes but local scripts can only be used inside players, tools, guis, and i forgot if there’s anything else
if what you’re trying to animate is a NPC then you literally HAVE to use server scripts
I got a response on another thread talking about making animations events manually using keyframe timers so that solves that problem but I’m not sure about the fact about playing NPC’s animations client side to save performance
Here is the thread where a got this answer
playing npc’s animations client side??? what???
but then how are you going to replicate those animations to every other client, via :FireAllClients()??
it’s just unnecessary amounts of additional code that could very much be skipped by just playing the animations on a server script
not to mention that you would have to check whether an npc is close enough to play animation and if so play it, this will have severe performance issues
Ah well i didn’t know that… Thanks for clearing that up.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.