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

Stop script from picking the same player twice?

The goal of this code is to pick two different players and changing a value thats is within a folder within the player.

How do i go about making the code not pick the same player more then once?

players =  game:GetService('Players'):GetPlayers()

function getVip()
	return(players[math.random(1,#players)])
end

function getSniper()
	return(players[math.random(1,#players)])
end

while wait() do
	if #players >= 3 then
	getVip:WaitForChild('Values').teamValue = 'Vip'
	wait()
	getSniper():WaitForChild('Values').teamValue = 'Sniper'
	
	end
end

1 answer

✓ Accepted answer

What you can do is combine your two functions into the while loop, and use the table.remove function to ensure that the Player chosen for the VIP is not the same player that will be chosen for the Sniper.

#####Note: you should define the players variable inside the while loop so that it updates with each iteration.

while wait() do
	local players = game.Players:GetPlayers()
	if #players >= 3 then
		local vip = table.remove(players,math.random(#players))
		local sniper = players[math.random(#players)]

			--Change values

	end
end

1 comment

0

Thanks

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