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!
This might work, try getting the character like this
workspace[Player.Name]
I'm just guessing
Solved it myself after messing with it for a while.
What I did is change PlayerRemoving
to PlayerAdded
. That way, it always registers when the character either dies or disconnects. Works now!
Thanks for all the answers on this question as well.