Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make it so a 4 random players are picked, and it changes their clothes, all differently?

Asked by 10 years ago
assets={}
    assets.Shirt{90415298,114883953,140974162,81050287,112047296,92448971} --Shirts
    assets.Pants{65160698,89224181,67492557 } 
    assets.Hats= game.Lighting.Hats:GetChildren() -- hats go in a model under lighting called Hats

player =  game.Players.LocalPlayer -- gets the player
a = player .Character:GetChildren() -- Gets parts used for cleaning

function Clear() -- Removes hats Character meshes shirts and pants also T-shirts
for xX = 1,#a do
    if a[xX].ClassName=="Hat" or a[xX].ClassName=="CharacterMesh" or a[xX].ClassName=="Shirt" or  a[xX].ClassName=="Pants" or a[xX].ClassName=="ShirtGraphic" then
        a[xX]:Destroy()

    elseif a[xX].ClassName=="Part" and a[xX].Name~="HumanoidRootPart" then a[xX].Transparency = 0 
     end
    end
  end

Clear() -- Cleans the player
wait()
Shirt = Instance.new("Shirt",player.Character) shirts.Name = "Shirts"
pants = Instance.new("Pants",player.Character) pants.Name = "Pants"
hat = assets.Hats[math.random(1,#assets.Hats)]:Clone()
Shirt.ShirtTemplate = "rbxassetid://" .. assets.Shirt[math.random(1,#assets.Shirt)]
pants.PantsTemplate = "rbxassetid://" .. assets.Pants[math.random(1,#assets.Pants)]
hat.Parent = player.Character 

1 answer

Log in to vote
1
Answered by
TheMyrco 375 Moderation Voter
10 years ago

PUT THIS SCRIPT IN A NORMAL SCRIPT.

Your main problem is the fact that you're using a localscript, thus affecting every player (assuming that the script is automatically placed in the players).

Another problem was that you used the incorrect variable name at lines 21 ("shirts") and there was a space between the the dot and word player in line 7.

Script order (so you can see what I did where and how): Lines 1 - 6: Creating variables which we will need later. Lines 8 - 16: Creating a function to 'clean' the player. The function parameter is the player, which will be passed to the function when called. Lines: 18 - 36: Creating a function to pick 4 players. The players must have a Character. The function checks if the same person isn't picked twice by repicking if it finds that that person had already been picked before. Lines 38 - 50: Here we just combine our functions and variables to (in order) 1) get the players, 2) 'clean' them, 3) dress them.

local amountOfPlayers = 4 -- how many players will be picked
local assets = {
    ["Shirt"] = {90415298,114883953,140974162,81050287,112047296,92448971};
    ["Pants"] = {65160698,89224181,67492557 };
    ["Hats"] = game.Lighting.Hats:GetChildren();
}

function Clear(x) -- Removes hats Character meshes shirts and pants also T-shirts
    for _,v in pairs(x.Character:GetChildren()) do
        if v:IsA("Hat") or v:IsA("CharacterMesh") or v:IsA("Shirt") or  v:IsA("Pants") or v:IsA("ShirtGraphic") then
            v:Destroy()
        elseif v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then 
            v.Transparency = 0 
        end
    end
end

function pick(amount)
    local players = {}
    local already = false
    repeat 
        wait()
        local player = game:GetService("Players"):GetPlayers()[math.random(1, #game:GetService("Players"):GetPlayers())]
        for _,v in pairs(players) do
            if player == v then
                already = true
                break
            end
        end
        if not already then
            table.insert(players, player)
        end
        already = false
    until #players == amount
    return players
end

local people = pick(amountOfPlayers)
for _,v in pairs (people) do
    Clear(v)
    local Shirt = Instance.new("Shirt", v.Character) 
    Shirt.Name = "Shirt"
    Shirt.ShirtTemplate = "rbxassetid://" .. assets.Shirt[math.random(1, #assets.Shirt)]

    local pants = Instance.new("Pants", v.Character) 
    pants.Name = "Pants"
    pants.PantsTemplate = "rbxassetid://" .. assets.Pants[math.random(1, #assets.Pants)]

    assets.Hats[math.random(1, #assets.Hats)]:Clone().Parent = v.Character
end
Ad

Answer this question