Need help getting newly joined player id

im trying to fix my code that i talked about in another post: Need help making multiple scripts with similar code run correctly and im wondering if i can get the newest joined users id and make my model only disappear if that id leaves the game, if anyone knows how to pull this off i would appreciate it a lot
my current code:
image

you basically make a variable but before that let’s get the basic preparations said, you make a server script in the server script storage, make some variable in the first lines of the script then you make a player added function

now what you do in the player added function is that you overwrite the variable with the player param you got from the player added function, then you write in basically the simplest part or plr.UserId

1 Like

Can’t you do something like:

local currentID;
function onPlayerAdded(player)
	currentID = player.UserId;
	...
end;

function onPlayerRemoving(player)
	if(currentID == player.UserId) then
		**hide model**
	end;
	...
end;

Note: I left “hide model” empty since I do not know how you want to hide it (destroying, hiding each part inside, etc…)

Edit: This is exactly the same to what @reygenne1 suggested.

Using the for loop you already have:

local currentID;
function onPlayerAdded(player)
	currentID = player.UserId;
	for _, part in pairs(Model:GetDescendants()) do
		if part:IsA("BasePart") then
			part.Transparency = 0;
			part.CanCollide = true;
		end;
	end;
end;

function onPlayerRemoving(player)
	if(currentID == player.UserId) then
		for _, part in pairs(Model:GetDescendants()) do
			if part:IsA("BasePart") then
				part.Transparency = 1;
				part.CanCollide = false;
			end;
		end;
	end;
end;

i didn’t read the post in depth properly but anyways, to change some things up that correlates more with the main problem within the topic you’re clueless about, this won’t require table as that is for more complicated issues.

so what you want to do first is assign a suit (which is the issue your facing) but instead of some complex things like those most people tell you for more easier purposes, name it something like the original and then connect the latter with the userID for example;

suit.Name = "suitcase"..tostring(plr.UserID) which in correct terms will project suitcase95939482 like since that is mine and i am being the example because this code will not backfire and for the player removing function, you want to get the UserID of the player that’s leaving then compare it to a possible suitcase that has the tag then delete it, or if not then don’t do anything about it if that may somehow occur

apologies for not understanding how to do this but how do i compare the id to the suitcase name?

local id = plr.UserID

you basically then administer a findfirstChild for child loop onto the workspace or the object that is the main parent of the suitcases then look for one that has the same userID like this

if string.find(v.Name, "suitcase"..plr.UserID) then

sorry im not sure what you mean by the findfirstchild loop, could you help me with the code? all the suitcase models are just in the workspace.
heres my code so far:
image

Keep in mind that not everyone may understand the terminology that you’re using, so try to keep it clear and simple for everyone.