How Do I Set A Dummy To The Character


I Want It Where Some One Joins It Sets Dummy One To There Skin And When They Leave It Goes Back To The Dummy

Lets Say When Player 2 Joins Player 1 Dummy 2 Gets Player 2 skin and when player 1 leaves and dummy 1 gets back to normal dummy then player 3 joins it gets dummy 1

i hope you understand that

game.Players.PlayerAdded:Connect(function(player)
	local Character = game.Players:CreateHumanoidModelFromDescription(game.Players:GetHumanoidDescriptionFromUserId(player.UserId), Enum.HumanoidRigType.R6)
	Character.Parent = game.ReplicatedStorage.AssetFolder.Characters
end)

i got this as the script but its not working thats why im here

1 Like

Is the Character actually in workspace? I thinks that’s the first thing you should check.

Edit: By the way, what isn’t working?

You can create a table to keep track of what person is who, like for example:

TakenCharacters = {
    [1] = Player1
    [2] = Player2
    [3] = Player3
    [4] = Player4
}

With that kind of system, you can then check if the Player leaves the game, check if they are one of the characters an what number they are, and then remove it from the Table, to make this simpler you can assign a ObjectValue to the Current Player with that Character, when they leave, you can remove them from the ObjectValue or the table, and when another Player Joins, you can assign them by that character by doing a simple check whether the Current Value is nil (meaning no value), Lets say Player1 Left the game, and Player5 joined the game, we would want it to assign that player to the table, which would look like this:

-- When Player1 Left:
TakenCharacters = {
    [2] = Player2
    [3] = Player3
    [4] = Player4
}
-- When Player5 Joined
TakenCharacters = {
    [1] = Player5
    [2] = Player2
    [3] = Player3
    [4] = Player4
}

When they are Assigned, you can then get the Data for their Character, and Apply it to the coresponding Dummy.

1 Like

i shouldve clarified when i set the humanoid desription in the workspace it loses all its children

Ah, but I believe @DasKairo ‘s post is the solution. Maybe try that (well after resolving the issue you listed)

Could you possibly provide all the code you’re using to load the characters?

so somthing like this?

local Players = {}

game.Players.PlayerAdded:Connect(function(player)
	table.insert(Players, player)
end)

game.Players.PlayerAdded:Connect(function(player)
	table.remove(Players, player)
end)

Uhm I’m not sure if I’m going to interpret @DasKairo ‘s response correctly. But here’s what they kinda mean:


local Players = {
[1] = nil,
[2] = nil,
[3] = nil,
[4] = nil
}

game.Players.PlayerAdded:Connect(function(player)
if Players[1] == nil then
Players[1] = player.Name
elseif Players[2] == nil then
Players[2] = player.Name
elseif Players[3] == nil then
Players[3] = player.Name
elseif Players[4] == nil then
Players[4] = player.Name
end
end)

game.Players.PlayerAdded:Connect(function(player)
	for i, v in pairs(Players) do
if v == player.Name then
Players[v] = nil
end
end
end)

Then using this data, you can load the characters manually like so:


local Character = game.Players:CreateHumanoidModelFromDescription(game.Players:GetHumanoidDescriptionFromUserId(player.UserId), Enum.HumanoidRigType.R6)

if Players[1] == nil then
-- Your Code Here
elseif Players[2] == nil then
-- Your Code Here
elseif Players[3] == nil then
-- Your Code Here
elseif Players[4] == nil then
-- Your Code Here
end

This is my interpretation. I don’t know if this might actually work for you or not.

i cant seem to find out how to get there character onto the dummy

Found this post for you:

Try this:

-- // Services
local Players = game:GetService("Players")

-- // Variables
local Dummies = workspace.Dummies:GetChildren()

local DummyCharacters = {}

-- Setup all the dummies into the table
for _, dummy in pairs(Dummies) do
	table.insert(DummyCharacters, {Model = dummy, Player = nil})
end

-- // Functions
Players.PlayerAdded:Connect(function(Player)
	
	-- Loop through all the dummies
	for _, dummy in DummyCharacters do
		
		-- Check if the dummy doesn't already have a player assigned and if it has a Humanoid object
		if not dummy.Player and dummy.Model:FindFirstChild("Humanoid") then
			
			-- Get the HumanoidDescription
			local HumanoisDescription = Players:GetHumanoidDescriptionFromUserId(Player.UserId)
			
			-- Apply the HumanoidDescription and set the player
			dummy.Model:FindFirstChildOfClass("Humanoid"):ApplyDescription(HumanoisDescription)
			dummy.Player = Player
			
		end
	end
	
end)

thats close but its setting all of the dummies to my character

It shouldn’t, do you have them setup like this?
image

Screenshot 2023-06-02 003855
thats what the script is doing
Screenshot 2023-06-02 003905
this is how i have my folder setup

Should be fixed with this:
Also added the part you mentioned where its reset when a player leaves.

-- // Services
local Players = game:GetService("Players")

-- // Variables
local Dummies = workspace.Dummies:GetChildren()

local DummyCharacters = {}

-- // Setup

-- Insert all dummies into the table
for _, dummy in pairs(Dummies) do
	table.insert(DummyCharacters, {Model = dummy, Player = nil})
end

-- // Functions

-- Player joins the game and set one of the available dummise to the player
Players.PlayerAdded:Connect(function(Player)
	
	-- Loop through all the dummies
	for _, dummy in DummyCharacters do
		
		-- Check if the dummy already have a player assigned and if it has a Humanoid object
		if not dummy.Player and dummy.Model:FindFirstChild("Humanoid") then
			-- Set the player
			dummy.Player = Player
			
			-- Get the HumanoidDescription
			local HumanoidDescription = Players:GetHumanoidDescriptionFromUserId(Player.UserId)
			
			-- Apply the HumanoidDescription
			dummy.Model:FindFirstChildOfClass("Humanoid"):ApplyDescription(HumanoidDescription)
			
			return
		end
		
	end
	
end)

-- Player leaves the game and remove the player from any dummies they are "attached" to
Players.PlayerRemoving:Connect(function(Player)
	
	-- Loop through all the dummies
	for _, dummy in DummyCharacters do
		
		-- If the dummy has the player
		if dummy.Player == Player then
			
			local Humanoid = dummy.Model:FindFirstChildOfClass("Humanoid")
			
			-- Create new HumanoidDescription
			local NewDescription = Instance.new("HumanoidDescription")
			
			-- Set all the body colours to Medium Stone Grey
			NewDescription.HeadColor = Color3.fromRGB(163, 162, 165)
			NewDescription.LeftArmColor = Color3.fromRGB(163, 162, 165)
			NewDescription.LeftLegColor = Color3.fromRGB(163, 162, 165)
			NewDescription.RightArmColor = Color3.fromRGB(163, 162, 165)
			NewDescription.RightLegColor = Color3.fromRGB(163, 162, 165)
			NewDescription.TorsoColor = Color3.fromRGB(163, 162, 165)
			
			-- Apply the description
			Humanoid:ApplyDescription(NewDescription)
			
		end
	end
end)

it looks like it works my friends isnt online to test it out rn so ima have to test it tommarow

You can test it in studio, go to “Test” and set the player amount to 2 and press "Start’
Note: You will have to set the user id in the script to yousr or someone elses otherwise it will error as the players in tests have user ids of -1 and -2.

local HumanoidDescription = Players:GetHumanoidDescriptionFromUserId(1210019099)

image

by the looks of it it works thx man

1 Like

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