Lobby dummy script help

How to make it so that when only one used dummy is used, the rest disappear, etc. The script is below.

local Dummies = {
	workspace.Folder.Dummy1,
	workspace.Folder.Dummy2,
	workspace.Folder.Dummy3,
	workspace.Folder.Dummy4

}

local LastDummy = nil

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

	local Dummy

	if LastDummy == nil then LastDummy = 1 end

	Dummy = Dummies[LastDummy]

	local Hum = Dummy.Humanoid
	local UserId = Player.UserId

	Hum:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(UserId))
	LastDummy += 1

end)

2 Likes

Add this before your last end.

for index, DexedDummy in pairs(Dummies) do
 if index ~= LastDummy then
  DexedDummy.Parent = game.ServerStorage
 else
  DexedDummy.Parent = workspace.Folder
 end
end
2 Likes

1 Like

worked out for me not sure what may be your issue with them not spawning in.

local Dummies = {
	workspace.Folder.Dummy1,
	workspace.Folder.Dummy2,
	workspace.Folder.Dummy3,
	workspace.Folder.Dummy4
}

local LastDummy = nil

game.Players.PlayerAdded:Connect(function(Player)
	local Dummy

	if LastDummy == nil then LastDummy = 1 end

	Dummy = Dummies[LastDummy]

	local Hum = Dummy.Humanoid
	local UserId = Player.UserId

	Hum:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(UserId))
	
	for index, DexedDummy in pairs(Dummies) do
		if index == LastDummy then
			DexedDummy.Parent = workspace.Folder
		elseif index ~= LastDummy then
			DexedDummy.Parent = game.ServerStorage
		end
	end
	
	task.wait()
	LastDummy += 1
	print(LastDummy)
end)

1 Like

Now only one appears.

1 Like

Isn’t this what you said you wanted, though?

Okay, I actually constructed that sentence incorrectly. What I meant was that when there’s, for example, 1 player, there’s one dummy. When there are 2 players, there are 2 dummies, and so on. I apologize for my mistake.

That makes sense. You can alter the code as such:

-- please use getservice and not game.
-- this should be at the top of your script
-- `workspace` is an exception - it's ok to use
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

-----------------------------------------------
-- after the ApplyDescription
        local playerCount = #Players:GetPlayers() -- get count of players

        -- the idea is to make dummies appear as long as their index is below the amount of players
        -- so dummy 4 would not appear with 3 players, but dummies 1,2,3 will
	for index, DexedDummy in pairs(Dummies) do
		if index <= playerCount then
			DexedDummy.Parent = workspace.Folder
		else
			DexedDummy.Parent = ServerStorage
		end
	end

-- before the task.wait()
-----------------------------------------------
2 Likes

Okay, everything is working. I have one last question. Would it be possible that when the player disconnects, the dummy also disappears?


2 Likes

Depending on how your setup is, you can use game.Players.PlayerRemoving event and bind the corresponding dummy to deletion

2 Likes

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