I have this Heartbeat command that moves an NPC to a player and detects when its close enough to attack. However i need to send some kind of signal to a local script to play an animation when this happens. The problem is if i just put a remote command in it over loads and gives me the “Remote function invocation queue exhausted” error. Anyone know a way around it?
RunService.Heartbeat:Connect(function()
local nearestPlayer, distance, direction = FindNearestPlayer()
if nearestPlayer then
if distance <= TargetDistance and distance >= StopDistance then
NPCHumanoid:Move(direction)
else
NPCHumanoid:Move(Vector3.new())
end
if distance <= AttackDistance and tick() - LastAttack >= AttackCooldown and NPCModel:GetAttribute("Stunned") == false then
--runs when attacking
LastAttack = tick()
i need to local script to be detecting that the player is in range from the server script so i assumed that i would update the local script in the heartbeat. this specific script also crashes when i use something like a while true
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.
Remote function invocation queue exhausted only happens if the request has timed out for a RemoteFunction, not a RemoteEvent, by not hooking a listener.
Your code does not even show where it is firing the RemoteEvent. However, you can manually rate limit the RemoteEvent itself.
You can play animations server-side - you’re probably doing it wrong.
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))
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.
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.
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