There seems to be an issue upon accessing character from the PlayerRemoving event. The weird thing is that I can get to character from a ClickDetector.MouseClick call. Any idea as to why this is acting like this?
Here's my code:
game.Players.PlayerRemoving:Connect(function(player)
print(player.Backpack)
for i,v in pairs(player.Character:GetChildren()) do
if v.ClassName == "Tool" and v:FindFirstChild("RoomNumber") ~= nil then
v.Parent = player.Backpack
end
end
for i1,v1 in pairs(player.Backpack:GetChildren()) do
if v1.ClassName == "Tool" and v1:FindFirstChild("RoomNumber") ~= nil then
for i2,v2 in pairs(script.Parent.RoomScreen.Rooms:GetChildren()) do
if v2.Name == v1.RoomNumber.Value then
v2.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
return
end
end
end
end
end)
As you can see, this is a hotel room script and I want this to work because when a player leaves without checking out, I want to make the room available again. Any ideas as to why accessing character doesn't work?
Thanks for your help!

7 comments
Welp, that should work, what's wrong? any errors or just nothing happening?
There is an error. I go into test mode, get myself a room (the rest of the code works) and it says the room is booked (color is red). When I leave, I made it print a message so I know it is working, but I get this error: Workspace.CheckInSystem.CheckIn.StaffCheckIn.CheckIn.Screen.MainScreen.Script:84: attempt to index field 'Character' (a nil value)
Have you referenced the character as "Player.Character or Play.CharacterAdded:Wait()" ?
Player.Character. Should I do CharacterRemoving too?
yah, maybe as Psudar said the character doesnt exist yet, but that wouldnt make sense actually since i assume the character must've loaded since you checked the room and started playing
try CharacterRemoving yeah
Throws no error and does nothing.