NPC passed as arguement lost on SendToLocal

Describe the bug:

How do you cause this bug?

  • List the steps

Trying to :Show() a widget to single client. Widget is attached to NPC.
Script on the NPC sends itself to a script running on the user using Adams LocalHandler package.
DoOnLocal loses the NPC entity upon being local

function LocalHandlerScript:DoOnLocal(entity, functionName, …)
print(“This should always print…”)
print(“Local Handler Called - functionName…”,functionName)
print(“Entity is:”,entity:GetName())
if self:GetEntity():IsLocal() then
print(“This is local sending…”)
entity:SendToScripts(functionName, …)
print(“Not local!”)
self:SendToLocal(“DoOnLocal”, entity, functionName, …)

[Server] Sending DoOnLocal
[Server] This should always print...
[Server] Local Handler Called - functionName..    ClientShowChevron
[Server] Entity is:    nPC1TankDynamic91165
[Server] Not local!


[Client] This should always print...
[Client] Local Handler Called - functionName..    ClientShowChevron
[Client] [Error] localHandlerScript:13: attempt to index local 'entity' (a nil value)
stack traceback:
    localHandlerScript:13: in function <localHandlerScript:10>

Screenshots / video of bug:

Which platform: PC 

Which input:  keyboard + mouse

Your Crayta username: Arescaries

Game seen in (including "Hub" or "Editor for XYZ"): All

How regularly do you see this? (E.g. 2/3 times - please try 3 times if possible): Everytime

Time + date seen:

Version number (found in Help tab in Settings): 

(PC only) hardware specs (upload dxdiag file if possible - 

The more information you provide, the more likely it is that this bug can be fixed quickly! Also, if this was discussed in Discord / Reddit / elsewhere, it might help to include a screenshot of that discussion!

Hey there @AresCaries

:star2: :rainbow: Welcome to the Crayta Forum! :rainbow: :star2:

Thank you for taking the time to submitting this issue into the Forums.
I have created a ticket in our system so our Internal Team can investigate this further.

Hi @AresCaries thanks for submitting this bug report.
I’m the creator of the LocalHandler package, and looking at your report here, I believe this is more of a misunderstanding of how the package is intended to work, rather than a bug.

To call a function on just a single client, say, “Adam’s client”, that function needs to be passed to their local client via an entity owned by their client - either “Adam’s User” entity or “Adam’s Player” entity. Calling “SendToLocal” on an entity that isn’t tied to a specific client, means it won’t know which 1 client to go, as there could be many clients connected to your game.

The way to use the LocalHandler is as a way to pass messages FROM a world entity (like your NPC), VIA a specific User, back to the client’s version of that world entity (your NPC), so that it knows which user’s client to call the function on.

You’ll want to do these steps to get your desired outcome:

  • Put the LocalHandler script onto the User template
  • In your NPC script, send the function via the user, like this - user:SendToScripts("DoOnLocal", self:GetEntity(), "ClientShowChevron" - where user is the user entity for the client who you want to show the chevron for.

Hopefully that makes sense. Let me know if you have any more questions!