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

How do I randomize a value in every player and have all values be different?

Asked by
tber8 37
7 years ago

I am trying to use values on players as codes for their roles in a game. I cannot think of a way to randomize the values in the players without some values being the same.

My only attempt:

local numhelp = Instance.new('NumberValue')
numhelp.Value = game.Players.NumPlayers

for _,v in pairs(game.Players:GetChildren()) do
    local num = numhelp.Value
    v.CharType = num
    numhelp.Value = numhelp.Value - 1
    end
end

It took me a while to think this up, but it isn't randomized. I need help randomizing the values without alike values. I am trying also to get the randomization numbers to go from 1 to the number of players.

0
You could check out http://wiki.roblox.com/index.php?title=Random_numbers It will be useful for you. iDarkGames 483 — 7y
0
thanks tber8 37 — 7y
0
you also have a extra *end* wich will error. RubenKan 3615 — 7y
0
but how do i make different randomizations to be all different numbers? tber8 37 — 7y
View all comments (2 more)
0
the end was a part of the while true loop for the game tber8 37 — 7y
0
i posted a code fix (hopefully) in the answer section rustyhuskey 59 — 7y

1 answer

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

Code Fixed

local numhelp = Instance.new('NumberValue')

for _,v in pairs(game.Players:GetChildren()) do
    if v.numhelp == nil then
    local Val = Instance.new('NumberValue',v)
    Val.Value=0
    end
    v.numhelp.Value = math.random(1,game.Players.NumPlayers)
    v.CharType = numhelp.Value
end

math.ranodm(1,4) is the numbers you want it to go to as seen now it will go to a random number between 1 and players in the game. With 1 and players in the game included as a option to be chose!

Hopefully this answer your question as I don't really know what your trying to do here!

0
That or If you have a value call CharType. You can do "v.CharType = math.random(1,game.Players.NumPlayers)" rustyhuskey 59 — 7y
0
Thanks tber8 37 — 7y
0
Does this make some values equal? I was looking for a way to make them all different. tber8 37 — 7y
Ad

Answer this question