Hello.
I am currently experimenting with the Players.PlayerRemoved event, and I was wondering, is it possible for the game to detect if a specific player has left the game, from a Player gotten from the GetPlayerFromCharacter(hit.Parent) function. I have attempted this in a script, and what's supposed to happen is that when the player claims an aquarium, it sets the pad text to their name, and makes it unclaimable afterwards. I want to make it so that when the player leaves, the aquarium frees up and another player can claim it. I have attempted to use the Players.PlayerRemoved event with a specific player but it has not worked.
Here is my script:
local Pad = script.Parent
local Debounce = false
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:WaitForChild("Remote Events (Main)")
local IsClaimed = Pad.Parent.IsClaimed
local Aquariums = workspace.Map.Aquariums
Pad.Touched:Connect(function(hit)
local Player = Players:GetPlayerFromCharacter(hit.Parent)
local Character = Player.Character
local ClaimedValue = Player.PlayerGui.AquariumClaimed
if not (Debounce) then
Debounce = true
if IsClaimed.Value == true then return end
else
if ClaimedValue.Value == true then
else
Aquariums.PlayerPad1:FindFirstChild("Name Tag").NameUI.Username.Text = hit.Parent.Name
RemoteEvents.Data:FireClient(Player)
script.Disabled = true
script.Parent.Process.Disabled = false
ClaimedValue.Value = true
IsClaimed.Value = true
end
wait(1)
Debounce = false
if IsClaimed.Value == true and Player then
Players.PlayerRemoving:Connect(function(LocalPlayer)
Aquariums.PlayerPad1:FindFirstChild("Name Tag").NameUI.Username.Text = "Not Claimed"
IsClaimed.Value = false
end)
else
return end
end
end)
I am unsure what is causing this issue, and would like some help. Thanks

3 comments
Put the Player Removing OUTSIDE of the touched event.
How would I go to make sure it fires only to a specific player leaving, in my case the player that has hit the part
You'd need to define a blank variable before the Touched function and assign it to the player after the part is touched. Only then do you check to see if that specific player leaves.