Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

6 comments

0

You could check out http://wiki.roblox.com/index.php?title=Random_numbers It will be useful for you.

0

thanks

0

you also have a extra end wich will error.

0

but how do i make different randomizations to be all different numbers?

0

the end was a part of the while true loop for the game

0

i posted a code fix (hopefully) in the answer section

1 answer

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!

3 comments

0

That or If you have a value call CharType. You can do "v.CharType = math.random(1,game.Players.NumPlayers)"

0

Thanks

0

Does this make some values equal? I was looking for a way to make them all different.

This discussion is preserved as it was. New answers, comments, and votes are closed.