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

Why Does This Character System Create Duplicates?

Asked by 6 years ago

In my game I have a character system, and while it works fine the game ALWAYS duplicates characters so there's more than 1 in a round. I don't want this. How can I fix it?

local Chars = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}
    for _, player in pairs(_G.playerlist) do
            if player and player.Character then
                local Humanoid = player.Character:WaitForChild("Humanoid")
                if Humanoid and Humanoid.Health > 0 then
                    characterselectednum = math.random(#Chars)
                    characterselected = game.ServerStorage.Characters[characterselectednum]
                    if game.Players:FindFirstChild(player.Name) then
                    table.remove(Chars, characterselectednum)
                    for i,v in ipairs(Chars) do
                        print("Character"..v)
                    end
                    local aye = Instance.new("StringValue")
                    aye.Parent = player
                    aye.Name = "PlayerName"
                    aye.Value = characterselected.CharName.Value    
                    local aye2 = Instance.new("StringValue")
                    aye2.Parent = player.Character
                    aye2.Name = "PlayerInfo"
                    aye2.Value = characterselected.CharInfo.Value
                    end
                    if game.Players:FindFirstChild(player.Name) then
                        local shirt = player.Character:FindFirstChild("Shirt")
                        pants = player.Character:FindFirstChild("Pants")
                        if shirt then
                            local charsthirt = characterselected:FindFirstChild("Shirt")
                            if charsthirt then
                                shirt.ShirtTemplate = characterselected.Shirt.ShirtTemplate
                            else
                                shirt.ShirtTemplate = 0
                            end
                        else
                            local charshirt = characterselected:FindFirstChild("Shirt")
                            if charshirt then
                                local shirt2 = charshirt:Clone()
                                shirt2.Parent = player.Character
                            end
                        end
                    end
                    if game.Players:FindFirstChild(player.Name) then
                    local shirtgraphic = player.Character:FindFirstChild("Shirt Graphic")
                    if shirtgraphic then shirtgraphic:Destroy() end
                    if pants then
                        local charpant = characterselected:FindFirstChild("Pants")
                        pants.PantsTemplate = characterselected.Pants.PantsTemplate
                    else
                        local charpant = characterselected:FindFirstChild("Pants")
                        local pantsy = charpant:Clone()
                        pantsy.Parent = player.Character
                    end
                    end
                            if game.Players:FindFirstChild(player.Name) then
                              for i,v in pairs (player.Character:GetChildren()) do
                                if v:IsA("Accessory") or v:IsA("Hat") then
                                    v:Destroy()
                                end
                            end

                            for i,v in pairs (characterselected:GetChildren()) do
                                if v:IsA("Accessory") then
                                    local rawr = v.Name
                                    if game.Players:FindFirstChild(player.Name) then
                                    local hato = player.Character:FindFirstChild(rawr)
                                    if not hato then
                                    local hat = v:Clone()
                                    hat.Parent = player.Character
                                    end
                                    end
                                end
                             end

                            if game.Players:FindFirstChild(player.Name) then
                            if player.Character.Head:FindFirstChild("Mesh") then
                            player.Character.Head.Mesh:Destroy()
                                local xd = Instance.new("SpecialMesh")
                                xd.MeshId = ""
                                xd.MeshType = "Head"
                                xd.Scale = Vector3.new(1.25, 1.25, 1.25)
                                xd.VertexColor = Vector3.new(1,1,1)
                                xd.TextureId = ""
                                xd.Offset = Vector3.new(0,0,0)
                            xd.Parent = player.Character.Head
                            end
                            end

                            wait(0.01)
                            if game.Players:FindFirstChild(player.Name) then
                            player.Character["Body Colors"]:Destroy()
                            local skin = characterselected["Body Colors"]:Clone()
                            skin.Parent = player.Character
                            end
                        end
                        player.Character.Head.face.Texture = characterselected.Head.face.Texture
                end
                wait(0.5)
            else
                table.remove(_G.playerlist, player)
                    _G.Players = _G.Players - 1
                end
            end
        end
0
you've posted just over a hundred lines of code. can you give us the chunk of which part is not working correctly? V_ChampionSSR 247 — 6y
0
that's the thing, i don't know which part is causing it to not work properly. BouncingBrenda 44 — 6y
0
So instead of narrowing down the situation, you expect one of us to ask the real question for you? T0XN 276 — 6y
0
how am i supposed to narrow down the situation if i dont even know what's causing it and that's what im trying to find out lmao BouncingBrenda 44 — 5y

Answer this question