Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my script acting stupid saying player is not in the game when it is?

So this function is run when a player leaves


function module.RemoveTable(Player)
	
	wait(30)
	
	if game.Players:FindFirstChild(tostring(Player)) then
		
		print(Player,' Is In The')
		
	else
		
		Mod[Player.UserId] = nil
		print('Was Destroyed')
	end
	
end

game.Players.PlayerRemoving:Connect(function(Player)

module.RemoveTable(Player)

but it keeps destroying the table even with the player in the game which means the game thinks hes not in the game

end)

1 comment

2

if Player is an object then use Player.Name I saw you using Player.UserId, tostringing the Player is like making a part a string...

1 answer

For starters, it's nothing to do with the script. Scripts have a reason for throwing an error. Right now, you're trying to cast a player to a string. Since that is not possible, the script will throw an error. If you wanted to tostring the player name, you would do this:

tostring(plr.Name)

if you wanted to tostring the id you would do this:

tostring(plr.UserId)

only things that can be cast are strings, ints, etc.

This discussion is preserved as it was. New answers, comments, and votes are closed.