so i would like to instantiate an event listener inside a function, yet am currently unaware of how to begin.
my guess of how to would be like this
function registerPlayer(player) --code player.Character.Torso.Changed:connect(watchPlayerLocation) end function watchPlayerLocation(CFrame) --code end
is this how i would set it up?
You're correct in theory, but the Changed
event does not fire when an object's Position changes.
If you want to have a function update based on Player positions, use the RenderStepped
event of the RunService
. Use it in a local script.
The connect
method returns a value, by the way. This 'ConnectionObject' has a disconnect
method (no parameters) that you can use to disconnect the function once it is no longer needed.