You can write your topic however you want, but you need to answer these questions:
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
What is the issue? Include screenshots / videos if possible!
i dont know how
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!
Yes,
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
wait()
if ItemsSpawned >= RandomNumber then
break
end
ItemsSpawned = ItemsSpawned + 1
local Clone = RandomItemFunction:Clone()
Clone.Parent = workspace.Jar.Items
if Clone:IsA("Model") then
Clone:SetPrimanyPartCFrame(CFrame.new(workspace.ItemSpawner.CFrame))
elseif Clone:IsA("BasePart") then
Clone.Position = workspace.ItemSpawner.Position
end
end
end
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
wait(1)
if i == 0 then
for i, v in pairs(Players:GetPlayers()) do
PlrGuess = Instance.new("IntValue", PlayerGuess)
PlrGuess.Name = v.Name
PlrGuess.Value = 0
end
local RandomNumber = math.random(250,10000)
for r = RoundTimer,0,-1 do
Status.Value = "How Much "..RandomItem.Name.." Are in the jar? ("..r..")"
wait(0.3)
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 "..game.ReplicatedStorage.PlrGuess:WaitForChild(v.Name).Value
end
end
end
end
end
end
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.
--Variables
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}
end
table.sort(Values,function(a, b)
return a[2] < b[2]
end)
for i = 1, #Values do
print(Values[i][1])
end
This would print those numbers from the closest one to 10. [Answer], you could modify it.
Hope it could help.
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.