I have this script which calculates highest vote and then after 10 seconds it chooses that map that got the highest votes:
But for some reason it keeps spawning exact same map. If you need more info I will give more.
I have this script which calculates highest vote and then after 10 seconds it chooses that map that got the highest votes:
But for some reason it keeps spawning exact same map. If you need more info I will give more.
Here should be a “better” version of you Map Selection code
local children = MapsFolder:GetChildren()
for i = 1,3 do task.wait()
local NextMap = children[math.random(1, #children)]
if not table.find(Maps, NextMap) then
table.insert(Maps, NextMap) -- inserts Map
table.remove(children, table.find(children, NextMap)) -- removes Map from table to not be selected again
end
end
It seemed to work but it is doing strange things. It’s not displaying all the maps and when the red map is on the screen and the highest votes are the pink one it still spawns the red
you may be able to do this:
for i = 1,3 do task.wait()
local NextMap = children[math.random(1, #children)]
if not table.find(Maps, NextMap) then
Maps[i] = NextMap -- Creates a Number Variable for the Map
Map[1]
is the First Map, and so on
It errors out the part where it says: table.sort(Maps) and I need this part in my script because it organises the maps in the table to display in screen
I think you really need table.sort()
here,
Since a Number is Assigned for the Map, it should be fine:
-- What Maps[i] basically does
Maps = {
[1] = Map1
[2] = Map2
[3] = Map3
}
print(Maps[1]) -- prints "Map1"
You can try this if you like:
table.sort(Maps, function(x, y)
return x > y -- or "x < y"
end)
Pretty much, If this is the effect you want:
00:42:22.417 â–Ľ { -- Before Sorting
[1] = "Hi",
[2] = "Hiiiiii",
[3] = "Hii",
[4] = "Hiiiii",
[5] = "Hiiii",
[6] = "Hiii"
} - Server - Script:15
00:42:22.417 â–Ľ { -- After Sorting
[1] = "Hi",
[2] = "Hii",
[3] = "Hiii",
[4] = "Hiiii",
[5] = "Hiiiii",
[6] = "Hiiiiii"
} - Server - Script:22
local List = {
[1] = "Hi";
[3] = "Hii";
[6] = "Hiii";
[5] = "Hiiii";
[4] = "Hiiiii";
[2] = "Hiiiiii";
}
print(List)
table.sort(List, function(x, y)
return x < y
end)
print(List)
x > y
will have this effect:
00:44:08.104 â–Ľ {
[1] = "Hiiiiii",
[2] = "Hiiiii",
[3] = "Hiiii",
[4] = "Hiii",
[5] = "Hii",
[6] = "Hi"
} - Server - Script:22
Ok now I fully understand how that works thanks. But I am a bit confused with the script. This is what I’ve got so far:
Do you have the client-side code responsible for letting players vote? Can you send it here?
By the way, use ``` when you are pasting code.
Example:
```
local Some_Code = “Some Text”
```
Above would show code like this:
local Some_Code = "Some Text"
Hi thanks for the reply. I forgot to let you know that I have figured out the problem.
As a suggestion, please do explain how you were able to figure out this problem, as others might have similar problems
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.