Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I keep getting this bug that every value is tied?

Asked by 6 years ago
Edited 6 years ago

When I manually change the value, it works but doesn't when changed in game??

Script is disabled at the start and enabled in another script when someone has pressed 'Vote' text button.

Changed to kikitobs answer - similar bug. It keeps saying every value is tied even though one value changes to 1 before script is enabled.

01local Voted
02local Tied = {}
03 
04for i,v in pairs(game:GetService("Lighting").Votes:GetChildren()) do
05    if Voted then
06        if v.Value > Voted.Votes then
07            Voted = {Votes = v.Value,Name=v.Name}
08            Tied = {}
09        elseif v.Value == Voted.Votes then
10            table.insert(Tied,v.Name)
11        end
12    else
13        Voted = {Votes = v.Value,Name=v.Name}
14    end
15end
View all 23 lines...

1 answer

Log in to vote
1
Answered by
Kikitob 105
6 years ago
Edited 6 years ago

Your current way getting the highest vote is really inefficent and it is doing way to many unneeded checks also changing the variable Mapvotes to {} after you disable it is just useless.

You can just loop trough the Votes children and check if the Voted value is higher then the last one. You should also just make it a variable what is voted instead of checking everything to see what it is.

Heres the rewritten script:

01local Voted
02local Tied = {}
03 
04for i,v in pairs(game:GetService("Lighting").Votes:GetChildren()) do
05    if Voted then --If it doesn't exist then it will not check if the Votes is higher then it to prevent attempted to compare number with nil error
06        if v.Value > Voted.Votes then --Checks if the votes are higher then the current stored one
07            Voted = {Votes = v.Value,Name=v.Name} --Set it to the stored
08            Tied = {}
09        elseif v.Value == Voted.Votes then
10            table.insert(Tied,v.Name)
11        end
12    else
13        Voted = {Votes = v.Value,Name=v.Name} --If it doesn't store a vote yet it will set it to the first one
14    end
15end
View all 23 lines...
0
Shows same bug, but this time with 'Colour Rush' Instead of Obby - Moved votes to ReplicatedStorage instead of lighting. willkiller13 43 — 6y
0
I edited the script so that it supports ties now. Kikitob 105 — 6y
0
It keeps saying every value is tied even though one value changes to 1 before script is enabled. willkiller13 43 — 6y
Ad

Answer this question