Detect if the player leaves or if the character is destroyed via tool script

The script is in the tool, the tool cant detect that, Because the tool is created a bit after the player joins.

This wouldnt work if there were multiple players with the same tool, and to detect if its the right player would need the same code thats used in my original script.

this is not a Local Script correct ?

It is not. It is a server script

the player leave function passes the Player Value so it should work just check if the player has it

it does not matter if we both had the same tool because the tools are still 2 different instances

did this, didnt work either.

either way id still prefer to not have to store the player just to check for when they leave.

Player Leave will never work in a script if that script is a child of the player

Okay, But then why did you say it should work? I stated that the script i am using is a child of the tool.

because i assummed you wanted the script to work if it was a Child of the Character Model then it could’ve worked when player leaves and you use GetPlayerFromCharacter i didn’t test

No it couldn’t have worked, because i already tested this while holding the tool.

you should be using Player leave and PlayerAdded on the server scipt service you should never use this multiple times it is bad practice and can cause Clashing between scripts. you should only need to use it once

server script service has nothing to do with this tool.

I guess i might have explained this wrong?

There is a tool, Which has a server script in it, Which has a hitbox system, and detects when the tool, character, or player is destroyed/leaves
My problem, is that the hitbox is only removed when the character is deleted, if the player leaves first, while the character is fine, The hitbox will stay.

Server Script service is used so the Server can handle things. Player Leaving is one of those things so the server script service has everything to do with this

The server script service does not have anything to do with this.

Yes, I know this, Im not that new of a developer.
Player leaving can be detected yes, But the server script is inside the tool, Not server script service. What is SSS Supposed to do with this script?

i am saying destroy the Hitbox from SSS not within the player that will never work

I cant do that.

Please read my other replies.

doesn’t matter if it is created within your Tool script SSS has access to anything

the hitbox is not a real part, the only way to get rid of it (its a spatial query) is by calling “Stop” from the module on the variable.
It has to be done this way, so im not sure what you mean.

oh my bad i thought the hitbox was an actual part. Ok so the Server scripts All scripts ClassName “Script” are all interConnected . Solution would be to fire a bindable from the Tool Script to the SSS for that to create the Hitbox and then do the player leave from there

Would this not be causing lag? i want my game to be as performant as possible