#Remote event not recieved (10-50%)
1 messages · Page 1 of 1 (latest)
SERVER
game.ServerScriptService.Events.NCP.NPCSpawn.Event:Connect(function(name,pos,plr)
--print("SPAWNING")
local cfg = game.ServerStorage.Penguins:FindFirstChild(name)
if not cfg then return end
--print("CFG")
if WorkstationsArray[plr.UserId] == nil then return end
if WorkerArray[plr.UserId] == nil then
WorkerArray[plr.UserId] = {}
end
--print("WORKAREA")
local SpawnPos = pos
table.insert(WorkerArray[plr.UserId],{name,Vector3.new(SpawnPos.X,SpawnPos.Y,SpawnPos.Z)})
remotes.NCP.SpawnNPC:FireClient(plr,name,#WorkerArray[plr.UserId],Vector3.new(pos.X,pos.Y + cfg.Parameters.Offset.Value,pos.Z))
local found = false
local object = nil
local GoalPos = nil
for key,v in pairs(WorkstationsArray[plr.UserId]) do
if found then break end
if v[2] == false then
for _,operation in pairs(cfg.Parameters.OperateableMachinery:GetChildren()) do
if operation.Value.Name == v[1] then
found = true
GoalPos = Vector3.new(tonumber(string.split(key,",")[1]),0.5+cfg.Parameters.Offset.Value,tonumber(string.split(key,",")[3]))
v[2] = true
object = v[3]
break
end
end
end
end
if found then
task.wait(1)
moveWork(plr,#WorkerArray[plr.UserId],GoalPos,cfg,object)
end
end)
Client
game.ReplicatedStorage.Remotes.NCP.PlayAnimNPC.OnClientEvent:Connect(function(uid,name)
print("BOB")
if workerArray[uid] == nil then return end
local worker =workerArray[uid]
local track = worker[1].AnimationController.Animator:LoadAnimation(worker[1].Animation[name])
track:Play()
playingAnim = track
end)
It is not printing bob somehow
never prints bob or prints bob 10-50% of the time? also, does the cfg check always pass in your NPCSpawn Event handler?
like does the whole NPCSpawn event handler execute 100% of the time but the client event is less consistent
Also, I think you may be hooked to the wrong event on the client
client
PlayAnimNPC.OnClientEvent
server
SpawnNPC:FireClient
Prints bob 90-50% of the time
oops sorry wrong code
local function moveWork(plr,uid,pos,cfg,obj)
--print(WorkerArray)
--print(WorkstationsArray)
local path = game.PathfindingService:CreatePath(agentParameters)
local success, errorMessage = pcall(function()
path:ComputeAsync(WorkerArray[plr.UserId][uid][2], pos)
end)
remotes.NCP.PlayAnimNPC:FireClient(plr,uid,"Walk")
if not success then
print(errorMessage)
elseif success and path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
for i,v in ipairs(waypoints) do
local nextpos
if not waypoints[i+1] then
nextpos = obj.End.Position
else
nextpos = waypoints[i+1].Position
end
local t = (WorkerArray[plr.UserId][uid][2] - (v.Position+Vector3.new(0,cfg.Parameters.Offset.Value,0))).Magnitude/cfg.Parameters.Speed.Value
remotes.NCP.MoveNPC:FireClient(plr,uid,v.Position+Vector3.new(0,cfg.Parameters.Offset.Value,0),t,nextpos)
--task.delay(t,function()
--remotes.NCP.MoveNPC:FireAllClients(uid,pos,0)
--end)
local p = Instance.new("Part")
p.Anchored = true
p.CanCollide = false
p.CanQuery = false
p.Size = Vector3.new(0.2,0.2,0.2)
p.Position = v.Position
p.Parent = workspace
task.wait(t)
WorkerArray[plr.UserId][uid][2] = v.Position
end
remotes.NCP.StopAnimNPC:FireClient(plr,uid)
remotes.NCP.WorkNPC:FireClient(plr,uid,obj)
end
end
Here @agile dragon
Also for more info, On some session like 1 play test it will work 100% of the time, But if it didn't work on another play test, it wont work 100% of the time
put warnings on every possible edge case
warn("A") warn("B") warn("C")
do that
or use breakpoints
in what function
Find a way to figure out where the logic is constraining
I mean, you need to figure out which side of the client-server boundary is unpredictably failing
So you need to do it to both
i would start with the one that executes the initial logic
ok1
cuz if it's that one then you don't gotta bother w the other
Huh strange, When I added warning, It worked 100% of the time (10 tests) when i removed it, It immediatly broke
the rates were around 50-70% (15 runs)
sounds like a thread scheduler issue
hmm so how can i fixs
You really shouldn't be sending so many different remotes at once, I'd just have a single remote and send behavior packets through it in bursts instead of having two different RemoteEvents FireClient one after the other
Ok
Umm but it is not firing like 20 times per sec its like about 1 time per sec for one event and 0.67 for another one
even still you're firing to different remotes for no reason