Detect if a specific player has left the game?
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:
01 | local Pad = script.Parent |
04 | local Players = game:GetService( "Players" ) |
05 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
07 | local RemoteEvents = ReplicatedStorage:WaitForChild( "Remote Events (Main)" ) |
08 | local IsClaimed = Pad.Parent.IsClaimed |
10 | local Aquariums = workspace.Map.Aquariums |
12 | Pad.Touched:Connect( function (hit) |
14 | local Player = Players:GetPlayerFromCharacter(hit.Parent) |
15 | local Character = Player.Character |
17 | local ClaimedValue = Player.PlayerGui.AquariumClaimed |
19 | if not (Debounce) then |
21 | if IsClaimed.Value = = true then return end |
23 | if ClaimedValue.Value = = true then |
25 | Aquariums.PlayerPad 1 :FindFirstChild( "Name Tag" ).NameUI.Username.Text = hit.Parent.Name |
26 | RemoteEvents.Data:FireClient(Player) |
27 | script.Disabled = true |
28 | script.Parent.Process.Disabled = false |
29 | ClaimedValue.Value = true |
30 | IsClaimed.Value = true |
34 | if IsClaimed.Value = = true and Player then |
35 | Players.PlayerRemoving:Connect( function (LocalPlayer) |
36 | Aquariums.PlayerPad 1 :FindFirstChild( "Name Tag" ).NameUI.Username.Text = "Not Claimed" |
37 | IsClaimed.Value = false |
I am unsure what is causing this issue, and would like some help.
Thanks