Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[ANSWERED] How can a LocalScript fire an event when the player changes Teams... efficiently?

Asked by 5 years ago
Edited 5 years ago

So let's say I have a LocalScript under StarterPlayerScripts with the following code:

local player = game.Players.LocalPlayer

local function onTeamChange(someArgs)
    --Do stuff on the client
end

...how can I get the onTeamChange() function to fire when the player changes teams?

I have some possible solutions:

  1. player.Changed event

Doing something like this:

player.Changed:Connect(onTeamChange)

and then check if the Changed property was "Team", or

  1. while true do loop that constantly checks for changes

or

  1. Since the Teams are always changed from a ServerScript, I could code in a RemoteEvent to always fire to all clients when the Teams are changed.

The thing is, I want to do this as efficiently as possible (by efficiently, I mean that it is less costly for the server/client, and thus does not generate much lag, even if there are many players in the server together) The problem with option 2 is that it is very inefficient, as the loop would be always running and it would contribute to lag for the potato computer players. The thing with option 1 is that it would fire every single time a property is changed, which I don't think is very efficient either, and the problem with option 3 is that there has to be a lot of server-client communication, especially when there are many people in the server.

So which of these would be the most effective/neatest to do? Which one would you use? Is it one of these, or have I overlooked something? Anything helps, thanks for your time :D

1
There is such a thing called GetPropertyChangedSignal(). DeceptiveCaster 3761 — 5y
0
oh. yup I overlooked something. Thx a lot :D RiskoZoSlovenska 378 — 5y

Answer this question