Local Handler package

Name: Local Handler

NOTE: This package MUST be used on the User template to work, it won’t work on other templates / entities (because it passes functions to one local client, attached to a specific User).

The Local Handler is a simple way to call a function only on a specific user’s client. For example, you might want to play a beep sound just for one user, like the Hunter in Prop Hunt, or make a wall invisible just for one user if they get an X-Ray vision power-up.

To use it, simply install, and drop the LocalHandler template onto your User template. Then when you want something in the world to only happen for one user, you can get a reference to that user and then call this line:
user:SendToScripts("DoOnLocal", theEntity, "theFunctionName", arguments)

For example, if you wanted to play a sound on one user, your code might look like this:

function SoundScript:PlayHitForUser(user)
    user:SendToScripts("DoOnLocal", self:GetEntity(), "PlayLocalSound", self.properties.hitSound)
end

function SoundScript:PlayLocalSound(sound)
    self:GetEntity():PlaySound(sound)
end
2 Likes

this is great thanks!

1 Like