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

One or more map poll text is not changing?

Asked by 3 years ago
Edited 3 years ago

Hello, I am trying to make a pool so player's can vote for a map but i got into a problem where three ( or less) of them get the names changed but a random one(or more) doesn't.. I can't find the solution could someone help me?

    for i,v in pairs(game.ReplicatedStorage.Assets.MapVote:GetChildren()) do
                    local RandomMap = Maps[math.random(1,#Maps)]
            if RandomMap.UsedFV.Value ~= true then
        if v:IsA("ImageButton") then
                    v.MapName.Text = RandomMap.Name
                            RandomMap.UsedFV.Value = true   
            end
            end
        end

https://imgur.com/a/RNHUpZ4

0
Just looking, you don't need to have the 1 in your math.random(1,#Maps). You just need math.random(#Maps) Roger111 347 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

There is a possibility of your code repeating the same map twice. What you could do is create an array containing all the maps, then as you choose a map remove it from the array so that the next iteration can't pick the same map.

local Maps = {'A', 'B', 'C', 'D', 'E'}

for i = 1, 4 do
    local Index = math.random(#Maps)

    print(Maps[Index]

    table.remove(Maps, Index)
end
0
Alright i mixed it with my code so it get's all the maps into a table and it works perfectly! thank you for helping me. Now i will don't need to deal with bool values. JustHentrix 4 — 3y
Ad

Answer this question