Make random character, bug + not work

Hi, i don’t know how i can make a random character system on spawn when the team of player is “Civil” here is the code template but no topics on what i want to do. It’s important, thanks for your time :happy3:

local charsFolder = game:GetService("ReplicatedStorage"):WaitForChild("Chars")

local debounceTimers = {}

local function pickRandomChar()
    local charList = charsFolder:GetChildren()

    return charList[math.random(#charList)]
end

local function changeCharacter(player)
    if player.Team.Name == "Civil" then
        local newChar = pickRandomChar()
        player:LoadCharacter(newChar.Name)
        print("loaded")
    end
end

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        local b = debounceTimers[player.UserId]
        if not b then
            table.insert(debounceTimers, player.UserId)
            changeCharacter(player)
            wait(1)
            local a = table.find(debounceTimers, player.UserId)
            table.remove(debounceTimers, a)
        end
    end)
end)

function table.find(t, what)
for _, v in pairs(t) do
if v == what then
return _
end
end
end

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
if not debounceTimers[player.UserId] then
debounceTimers[player.UserId] = true
changeCharacter(player)
wait(1)
debounceTimers[player.UserId] = nil
end
end)
end)

TEMPLATE

Thanks for your help :slightly_smiling_face:

If you’re using the template above, you don’t need to check if player is Civil. You can do that by removing the if statement in the changeCharacter function.

That not scripting at all, are you scamming ? Also i mean that just don’t change my character.

I am trying to help you that code was meant to fix your awful code.

Why send a shirt, then ? Also of what i said that just dont apply the character.

I fixed the bug and it’s work now.

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