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

How can I make this code use math to calculate and make 2/3 of all players "bloxxers"?

Asked by 6 years ago

im still a starter at scripting so I use tutorials but I can't find how to change the math on this script so it makes 2/3 of players in the game "bloxxers"

bloxxer = contestants [math.random(1, #contestants) ]

I just need help on how to make the math calculate 2/3 of players into "bloxxers"

0
is this code from stickmasterluke? ObStactionD3stroy3r 14 — 6y

2 answers

Log in to vote
2
Answered by 6 years ago

Really easy, to get the number of 2/3 of players, you can simply use

local numofbloxxers = (#game.Players:GetPlayers() / 3) --[[gets 1/3 of players]] * 2 --multiplies the number of 1/3 of players to get 2/3 of players.

Now, to make all ppl bloxxers, do this.

local bloxxers = {}

for i = 1, numofbloxxers do
table.insert(bloxxers, game.Players:GetPlayers()[i])
end

--do something with bloxxers table

Sorry that since I am on mobile, I cannot indent.

0
Won't this add the same players over and over again? H4X0MSYT 536 — 6y
Ad
Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago

This SHOULD work. Haven't tested. Don't call it the 'best' method. I'm not the 'best' scripter either.

local Bloxers = {}
local PlrNum = 0

for i, v (game.Players:GetChildren()) do    -- Loop through all objects where players are stored
    if v:IsA("Player") then                         -- Make sure object is a player
        PlrNum = PlrNum + 1                 -- Count players
    end
end

local BloxerCount = math.floor((PlrNum / 3) * 2)      -- Get bloxer ammount
local Count = 0

local A = game.Players:GetChildren()
while Count < BloxerCount do                                  -- Repeat for every bloxer needed
    local TempPlr = A[math.random(1, #A)]            -- Chose random player
    for i,v in ipairs(Bloxers) do
        if A ~= v then                                            -- Make sure player isn't allready a bloxer
            table.insert(Bloxers, A)                     -- Add player to list
            Count = Count + 1
        end
    end
end

Answer this question