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

How to make sure no BrickColor is repeated when changing a group of brick's BrickColor randomly?

Asked by 9 years ago
door = script.Parent  
local list = game.ServerStorage.Colors:GetChildren()
local list2 = game.Workspace.Colors4.pads:GetChildren()
local pm = game.ServerStorage.pm.Value
function onChatted(msg, recipient, speaker) 
local num = 0


local source = string.lower(speaker.Name) 
msg = string.lower(msg) 

if (msg == ":randomize") then 

repeat 

list2[math.random(#list2)].BrickColor = list[math.random(#list)].Value
num = num + 1
print(num)
wait()
until num == 9
end
num = 0
end 

function onPlayerEntered(newPlayer) 
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered) 

The script I have works fine but it has 1 problem. I do not want the color to be repeated onto any of the bricks. I tried using variables in a earlier version of this script but that did not work.

Thanks if you decide to help out, thanks if you just read this. - UltChowsk

2 answers

Log in to vote
0
Answered by 9 years ago
door = script.Parent  
local list = game.ServerStorage.Colors:GetChildren()
local list2 = game.Workspace.Colors4.pads:GetChildren()
local pm = game.ServerStorage.pm.Value
function onChatted(msg, recipient, speaker) 
    local num = 0
    --------------------------
    function colorCheck(tab,val) -- function, so you can do multiple times
        for _,v in pairs (tab) do
            if v == val.Value then
                return false
            else
                return true
            end
        end
    end
    ------------------------------
    local source = string.lower(speaker.Name) 
    msg = string.lower(msg) 
    -----------------------------------
    local colors = {} -- table for brickcolors
    -----------------------------------
    if (msg == ":randomize") then 

    repeat 
    ---------------------------------
    function change() -- so you can do multiple times
        local c = list[math.random(#list)]
        if colorCheck(colors,c) == true then
            list2[math.random(#list2)].BrickColor = c.Value
        else
            change()
        end
    end
    change()
    --------------------------------
    num = num + 1
    print(num)
    wait()
    until num == 9
    end
    num = 0
end 

function onPlayerEntered(newPlayer) 
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered) 


0
I put it in and got a stack overflow. UltChowsk 85 — 9y
0
Any idea how to prevent that? UltChowsk 85 — 9y
0
It may be becausen you used up all of the brickcolors available. TheDeadlyPanther 2460 — 9y
0
I have 9 seperate colors. Thats what the local variable list is for, I am trying to get it to pick from those 9 to change 9 different bricks without any repeats. UltChowsk 85 — 9y
View all comments (2 more)
0
Then it should work. TheDeadlyPanther 2460 — 9y
0
I got a stack overflow every time I tried. UltChowsk 85 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

I fixed it, I used another script to reset the values and it all works fine now. :D

Answer this question