Check if Player has certain range of Number Values

Not quite sure how to word this, but I wanted to see if there was a way to check if a player has a certain amount of points.

For Ex.

If the player has points in between the range of 100-200 then …
or if they have points in between the range of 200-300 points then…

local players = game:GetService("Players")

local function checkPlayerStats(statName, lowerThreshold, upperThreshold)
	local foundPlayers = {}
	for _, player in ipairs(players:GetPlayers()) do
		if player.leaderstats[statName].Value >= lowerThreshold and player.leaderstats[statName].Value <= upperThreshold then
			table.insert(foundPlayers, player)
		end
	end
	return foundPlayers
end
3 Likes
for _, v in pairs(game:GetService("Players"):GetChildren()) do
      local points = v:FindFirstChild("Points",true)
      if points and points.Value >= 100 and points.Value <= 200 then
            -- your code here
      end
end
1 Like

It is suitable for the way with more logical differences in each stage

local scoreDatas = {
	{
		score={0,100},
		runFunction = function()
			print("score0-100")
		end
	},
	{
		score={101,200},
		runFunction = function()
			print("score101-200")
		end
	},
}
local playerScore = 100
for _, scoreData in pairs(scoreDatas) do
	if playerScore >= scoreData.score[1] and playerScore <= scoreData.score[2] then
		scoreData.runFunction()
	end
end
1 Like