Values don't change when players leave the game

Hello. I’m trying to make a hotel for my roblox game. I want to make a script that detects if a player leaves and if the player that left was already checked in a room it checks them out from that respective room. I tried making a script myself and I even tested it with a friend, but when they left the “Owner” value was still their roblox username, and the “taken” value was still set to “True”. This is what I tried so far:

local Players = game.Players

Players.PlayerRemoving:Connect(function(plr)
	plr.CharacterRemoving:Connect(function()
		if game.Workspace.Room601.Door.Door601.Owner.Value == plr.Name then
			game.Workspace.Room601.Door.Door601.Owner.Value = "None"
			game.Workspace.Room601.Door.Door601.taken.Value = "False"
			game.Workspace.Key601.Transparency = 0
		end
	end)
end)

This is a server script in ServerScriptService. Any help is appreciated

2 Likes

simply remove plr.CharacterRemoving it shouldnt be used for when players leave the game

1 Like

Use Players.PlayerRemoving function instead to detect when the player is leaving.

1 Like

Wow… I really didn’t think it would be this easy, thank you!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.