NetRay - High-Performance Roblox Networking Library

Issue? I can’t seem to send a character Instance over NetRay.

So I noticed this when I updated my Netray from the old Deprecated NetRay 2.0 to this newer one and everything was working normally, however, I can’t pass my character instance and animation instance through my Player animator event.

The error is thrown by the Binary Encoder Script and it prints to the console
“[BE Dec] Inst fail: Workspace.SagePrismatic”
(Btw, when I click on this error, it’s leads to line 174 of the Binary Encoder script)

(Sorry if what I send is a bit too much/unnecessary but I’d rather send my whole code)
Here is the code for the Sever, I fire the event on line 59:

--Services
local ServerScriptService = game:GetService('ServerScriptService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ServerStorage = game:GetService('ServerStorage')

--Debounce
local NPCDebounces = ServerStorage.Combat.NPCDebounces
local Debounces = ServerStorage.Combat.Debounces

--[Modules]
local PlayerAnimator = require(ServerScriptService.Modules.PlayerAnimator)
local HitboxCreator = require(ServerScriptService.Modules.HitboxCreator)

--Settings
local Settings = require(script.BasicAttackSettings)
local SUCCESS,FAIL,RUNNING = 1,2,3

--Attacks
local Attacks = {
	Jab = Settings.Jab,
	Cross = Settings.Cross,
	Uppercut = Settings.Uppercut,
	['Front Kick'] = Settings["Front Kick"]
}

--VFX
local HitEffects = ReplicatedStorage.ParticleEffects.Combat
local EmptyEffect = HitEffects.BlankEffect

local Task = {}
function Task.run(obj)
	--Blackboard
	local CurrentAttack = obj.Blackboard['NextBasicAttack']
	local Blackboard = obj.Blackboard
	
	--Setting variables for the character model
	local Character = nil
	local Player = nil
	--Setting Player and Character 
	local NPCBool = Settings.CheckForNPC(obj)
	if NPCBool == false then Player = obj.Player end
	if NPCBool == false then Character = Player.Character else Character = obj.NPC end
	
	local Humanoid = Character.Humanoid
	
	--Attack Settings
	local AttackSettings = Attacks[CurrentAttack]
	--Setting Variables
	local HitboxOffset = CFrame.new(AttackSettings.HitboxOffset)
	local HitboxDuration = AttackSettings.HitboxDuration
	local DebounceTime = AttackSettings.DebounceTime
	local HitboxSize = AttackSettings.HitboxSize
	local HitEffect = AttackSettings.HitEffect or HitEffects.RegularHit
	local Damage = AttackSettings.Damage
	local Anim = AttackSettings.Anim
	local Attack = CurrentAttack
	
	--⚠️⚠️Animate and Create the hitbox
	PlayerAnimator.PushPlyrAnimations(Character, Anim) -- The Problem occurs when this is fired
	HitboxCreator.CreateHitbox(Character, Attack, HitboxOffset, HitboxSize, HitboxDuration, Damage, HitEffect, false)
	
	task.wait(DebounceTime)

	--Debounce removal
	if NPCBool == false then 
		Debounces:SetAttribute(tostring(Player.UserId), nil)	
	else
		NPCDebounces:SetAttribute(Character.Name, nil)
	end
	
	--Setup for next attack
	Humanoid:SetAttribute('NextSpecialAttack', AttackSettings.NextSpecialAttack)
	Humanoid:SetAttribute('NextBasicAttack', AttackSettings.NextBasicAttack)
	
	return SUCCESS
end
return Task

Then it goes to this module which fires to all clients: (This is most likely where the error occurs as it able to print the Character and animation before throwing an error)

--Services
local ReplicatedStorage = game:GetService('ReplicatedStorage')
--NetRay
local NetRay = require(ReplicatedStorage.Modules.NetRay)
--Event
local AnimationEvent = NetRay:RegisterEvent("PushPlyrAnimations", {
	priority = NetRay.Priority.HIGH,
	compression = true,
	batchable = true,
	rateLimit = {
		MaxRequests = 1,
		TimeWindow = 1,
		BurstWindow = 1,
		BurstLimit = 1,
	}
})

local module = {}

--Pushes Animations to all clients.
--The "Player" Variable is the Player the Animation is being done on.
function module.PushPlyrAnimations(Character, Animation, LoopBool, Weight, WeightFadeTime, WeightAdjustStartTime)
	print(Character)
	print(Animation)
	AnimationEvent:FireAllClients(Character, Animation, LoopBool or false, Weight or 0, WeightFadeTime or 0, WeightAdjustStartTime or 0)
end

return module

Then if it didn’t have an error it should fire to this Local script:

--Services
local ReplicatedStorage = game:GetService('ReplicatedStorage')

--NetRay
local NetRay = require(ReplicatedStorage.Modules.NetRay)
local PlayerAnimationEvent = NetRay:GetEvent("PushPlyrAnimations")

local function Animate(Character, Animation, LoopBool, Weight, WeightFadeTime, WeightAdjustStartTime)
	local Humanoid = Character.Humanoid
	local Animator = Humanoid:FindFirstChild('Animator')

	local Anim = Animator:LoadAnimation(Animation)
	
	Anim.Looped = LoopBool
	Anim:Play()
	
	if Weight > 0 then
		task.wait(WeightAdjustStartTime)
		
		Animation:AdjustWeight(Weight, WeightFadeTime)
	end
end

PlayerAnimationEvent:OnEvent(function(Character, Animation, LoopBool, Weight, WeightFadeTime, WeightAdjustStartTime)
	Animate(Character, Animation, LoopBool, Weight, WeightFadeTime, WeightAdjustStartTime)
end)

Additionally, I decided to do a quick test in another baseplate where I wait and then send my character through an event to the client where it will print the character’s name and this also resulted in the same error.

Test server script:

local NetRay = require(game:GetService('ReplicatedStorage').NetRay)

local Event = NetRay:RegisterEvent("ServerToClient")

task.wait(1)

Event:FireAllClients(workspace.SagePrismatic)

Test Client Script:

local NetRay = require(game:GetService('ReplicatedStorage').NetRay)

local Event = NetRay:GetEvent("ServerToClient")

Event:OnEvent(function(instance)
	print(Instance.name)
end)

1 Like

I will look into it, It’s probably the way instances are handled

for now you can just try send the players name and call it using that or similar

1 Like

I also found that you can’t seem to send animations over events so it seems like there is a massive issue in general with instances’ encoding/decoding.

For some reason on my main scripts it wouldn’t print out an error however I discovered that it wouldn’t work as the "Animation’ variable received on the client printed out as nil when tested.

I also then decided to test this on a regular baseplate and this time it actually gave an error msg:
[BE Dec] Inst fail: Workspace.Jab
This is the same one as last time.

Also heres the code for the test which prints out nil and an error
Server:

local NetRay = require(game:GetService('ReplicatedStorage').NetRay)

local Event = NetRay:RegisterEvent("ServerToClient")

task.wait(1)

local Anim = workspace.Jab

Event:FireAllClients(Anim)

Client:

local NetRay = require(game:GetService('ReplicatedStorage').NetRay)

local Event = NetRay:GetEvent("ServerToClient")

Event:OnEvent(function(instance)
	print(Instance.name)
end)

1 Like

NetRay v1.1.2

  • Updated Binary Encoder (v1.5.4)
  • Fixed instance handling with encoding and decoding
  • updated signalplus to v2.9.0

Both Roblox and GitHub Have been updated

Credit:
@SagePrismatic - for spotting the instance bug

3 Likes

Glad to hear that instances handling is fixed! I didn’t know this was a bug, I’m assuming its better to just send through a property rather than the whole instance through? Example instance.CFrame or the instance.Name depending on what you need? Love the Module it’s amazing, looking forward to all updates :smiley:

1 Like

Thank you, I appreacie the support!

as for

This is a more subjective case. If you just want to send the instances CFrame, then just send the CFrame data. If you want to send the entire instance reference through, then you can, but that would be up to you and your code’s needs, although it’s unlikely that you need to send an instance

1 Like