How would you grab the highest value in all models with the same value, and declare the person who has achieved that as a winner?

  1. What do you want to achieve? Keep it simple and clear!
    I want to wait 60 seconds, get the player who clicked a part with a ClickDetector the most and declare them as a winner through a StringValue in ReplicatedStorage.
  2. What is the issue? Include screenshots/videos if possible!
    I can’t seem to do this task.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried:
    1: To do it myself (I couldn’t think of a good way to do it)
    2: Looking on Google for some solutions (almost everything was about tables)
    3: Looking for solutions on other scripting sites for Roblox. (again, almost everything was about tables)
    Thanks,
    OldBo5

tables are by far the best way to do this, whether that be arrays or dictionaries,

With both, you can iterate though a generic for loop

Array Example

local Clicks = {[25] = "plr1", [22] = "plr2",[69] = "plr3"}
local TopScore = 0
local TopPlr

for i,v in ipairs(Clicks) do
   if i > TopScore then
      TopScore = i
      TopPlr = v
   end
end
print(TopPlr,TopScore) --plr3, 69

Dictionary Example:

local dict = {["plr1"] = 25, ["plr2"] = 22, ["plr3"] = 69}
local TopScore = 0
local TopPlr

for k,v in pairs(dict) do
   if v > TopScore then
      TopScore = v
      TopPlr = k
   end
end
print(TopPlr,TopScore) --plr3, 69
3 Likes

As @theking48989987 mentioned, table definitely are the best way to do this- using values simply creates more work than it solves- you would have to insert a value for every player that join; you would have to specify every value as its own variable or in a table, etc.

Try to avoid using workspace values in a scenario like this where you only need to do the job in one script.

1 Like