I am currently running into an issue when replicating destroy events from the server to the client.
Here is a timeline of what happens.
Player interacts with proximity prompt
Server receives interaction
Server destroys local script from target client’s character
Client unbinds actions as destroying event is called
Please note that the destroying event is handled in the same script that is getting destroyed by the server. Does this make it impossible to detect the destroying event?
The real question is- why destroy a script? It’s bad practice. Instead, you should build into the script that disables it from the inside by locking every function behind a debounce, or by just disabling the script instead of destroying it.
And to answer your question, no, it won’t work. Like I said, you should run the event function, then lock the script’s functions behind a debounce afterwards.
I am injecting a local script from the server whenever a player gets into a vehicle.
Can you explain what object you are injecting it into?
I inject the local script into the player’s character
Instead of doing that, you should try this.
- Create a Folder in
StarterCharacterScripts
named “Values”
- Add a Boolean, such as
"InVehicle"
into the folder, and set it to false.
- Add a LocalScript in
StarterCharacterScripts
, and make it do exactly the same thing the injected script would do, but inside of a function.
- Make said function fire when the
"InVehicle"
boolean sets to true.
- Cancel the function via messing around with parameters when the
"InVehicle"
boolean gets changed to false.
- Now, From the server, When the player steps into the vehicle, simply access the player’s character, access the
"Values"
folder, then access the "InVehicle"
boolean inside of said folder, and set it to true.
- Then, when the server detects the player leaving, simply set the
"InVehicle"
boolean to false.
Those are my tips/step-by-step explanation. Keep in mind that I can’t/will not help you write entire scripts, but I am happy to help if you’re stuck.