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
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:
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.
-- // 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)
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)
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)