Math.Random Or Random.new for Client Script

Im trying to make a math.random/Random.new for choosing a random player
My issue is a client gets a number and other client get other number. I try saving the number on a NumValue and still does not work. Any way to fix this?

local script

local CamYGame = game.ReplicatedStorage.Game.GAME.CamYGame
CamYGame.OnClientEvent:Connect(function()
	local Players = game:GetService("Players")
	local Camara = workspace.CurrentCamera 
	local Num = game.ReplicatedStorage.Game.GAME:WaitForChild("Num")
	local Character = Players:GetPlayers()[Num.Value].Character
	local Humanoid = Character:FindFirstChild("Humanoid")
	print(Humanoid, Character, Num.Value)
	if Humanoid then
		Camara.CameraType = Enum.CameraType.Custom
		Camara.CameraSubject = Character
	end
end)

Normal Script

local function Round() 
		local Num = Random.new():NextInteger(1, #Players:GetPlayers())
		local Ran = game.ReplicatedStorage.Game.GAME:WaitForChild("Num")
		Ran.Value = Num
		print(Num)
		for _,k in pairs(Players:GetPlayers()) do
			Players:GetPlayerFromCharacter(k)
			CamYGame:FireClient(k)
		end

Its there any way to fix this?

What is your current output and your expected output?
Are you running the round function multiple times consecutively?

Random.new(seed) can take in a seed parameter (integer). If this is the same, your random number calls will return the same value.

Output:

Player 1: Humanoid, Player1, 1 
Player 2: Humanoid, Player2, 1

I dont think is reseting but here is the code

local function Round() 
		local Num = Random.new():NextInteger(1, #Players:GetPlayers())
		local Ran = game.ReplicatedStorage.Game.GAME:WaitForChild("Num")
		Ran.Value = Num
		print(Num)
		for _,k in pairs(Players:GetPlayers()) do
			Players:GetPlayerFromCharacter(k)
			CamYGame:FireClient(k)
		end
		
	for i = RoundLeght, 0, -1 do
		wait(1)
		print("InGame " .. i)
	end
	print("Reseting")
	RoundEnd()
end

The random number value is the same for both players. Isn’t this what you want?

Yeah… Im trying to make like: if player 1 gets choosed on the math random then player 2 will force focus camara on him

Apparently I found a way to fix

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.