Getting a number nearest to the selected Number

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    getting a nearest number to a selected number, for example lets say the selected number is 10 and Player1 Guessed “1” and Player2 guessed “5” i want the guess to be nearest to the selected number
  2. What is the issue? Include screenshots / videos if possible!
    i dont know how
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
here is my script so far

local Status = game.ReplicatedStorage:WaitForChild("Status")
local Items = game.ReplicatedStorage:WaitForChild("Items")
local PlayerGuess = game.ReplicatedStorage:WaitForChild("PlrGuess")

local function SpawnItem(RandomNumber, RandomItemFunction)
	local ItemsSpawned = 0
	while true do
		if ItemsSpawned >= RandomNumber then
		ItemsSpawned = ItemsSpawned + 1
		local Clone = RandomItemFunction:Clone()
		Clone.Parent = workspace.Jar.Items
		if Clone:IsA("Model") then
		elseif Clone:IsA("BasePart") then
			Clone.Position = workspace.ItemSpawner.Position

local RandomItem = Items:GetChildren()[math.random(1,#Items:GetChildren())]

local IntermissionTimer = 10
local RoundTimer = 50
local Players = game:GetService("Players")

for i = IntermissionTimer,0,-1 do
	Status.Value = "Round Starting In: ".. i
	if i == 0 then
		for i, v in pairs(Players:GetPlayers()) do
			PlrGuess ="IntValue", PlayerGuess)
			PlrGuess.Name = v.Name
			PlrGuess.Value = 0
		local RandomNumber = math.random(250,10000)
		for r = RoundTimer,0,-1 do
			Status.Value = "How Much "..RandomItem.Name.." Are in the jar? ("..r..")"
			if r == 0 then
				for i,v in pairs(PlrGuess:GetChildren()) do
					if v.Value ~= math.min(RandomNumber - v.Value, RandomNumber + v.Value) then -- the Issue
						Status.Value = v.Name.." Has Won, His Guess is "

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Oh yea some of the scripts arent done so…

local Values = {3, 8}
local Answer = 10 

for i = 1, #Values do
	Values[i] = {Values[i], math.abs(Answer - Values[i])}
	--3 = {3,7}
	--8 = {8,2}

table.sort(Values,function(a, b)
	return a[2] < b[2]

for i = 1, #Values do

This would print those numbers from the closest one to 10. [Answer], you could modify it.
Hope it could help.

Ok thank you i will use this reply

any fixes idk what i did wrong?
when the intermission is 0 it creates a value called [The name of the player] example alirobloxerpro and value set to 0
then it makes a random number from 250 to 10000 and lets say the random number is 2692
and when the round finished it checks the Player Guessed and did everything you said

Remove .Value, you just need Values[n] to index each child. If the folder contains value objects and you want to index their ‘Value’ properties then you’ll need to do Values[n].Value.

now im getting this error

attempt to perform arithmetic (sub) on number and Instance

Because you need to index the instance’s ‘Value’ property.

oh i didnt read it uhmmmmmm ok

Values.Name should be Values[m].Name, Values.Value[m][1] should be Values[m].Value.

ok thanks let me try it maybe it will work

Thank you it worked but let me test more of it

You should probably mark this reply as the solution, I just helped fix the errors in your code.

i got an issue, everything works but when round ended it just sets all the value to 0 any fixes?

it sets all the player guess value to 0 idk why


Is another script responsible for changing the value object’s ‘Value’ properties?

no it dosent here is a video about it:
robloxapp-20220805-1704407.wmv (1.9 MB)

oh wait i fixed it i dont need the

for i = 1, #Values do
	Values[i] = {Values[i], math.abs(Answer - Values[i])}

that might be the supporter by it just changes the value