So I created a couple of game modes:
- Classic
- Randomizer
- Simon Says
The issue lies in Simon Says, I can’t figure out which loop is best in this scenario. Here is the chunk that runs the Simon says:
coroutine.wrap(function()
while true do
local simonPicker = math.random(#simonOrNot)
local simonPicked = simonOrNot[simonPicker]
-- print(simonPicked)
local colourPicking = math.random(#colourPicker)
local colourPicked = colourPicker[colourPicking]
local colourIndex = table.find(colourPicker, colourPicked)
-- print(colourPicked)
print(colourIndex)
ColourTiles(gamemodeClone.Tiles)
if simonPicked == "Simon says go to " then
for i = 5, 0, -1 do
status.Value = simonPicked..colourPicked..": "..i
wait(1)
end
for _,Part in ipairs(gamemodeClone.Tiles:GetChildren()) do
if Part:IsA("Part") then
if Part.Name ~= tostring(colourIndex) then
print("not = to colour index")
Part.Transparency = 1
Part.CanCollide = false
end
end
end
status.Value = simonPicked..colourPicked
wait(3)
elseif simonPicked == "Go to " then
for i = 5, 0, -1 do
status.Value = simonPicked..colourPicked..": "..i
wait(1)
end
for _,Part in ipairs(gamemodeClone.Tiles:GetChildren()) do
if Part:IsA("Part") then
if Part.Name == tostring(colourIndex) then
print("part = to colour index")
Part.Transparency = 1
Part.CanCollide = false
end
end
end
status.Value = simonPicked..colourPicked
wait(3)
end
round = round + 1
print ("round "..round)
for _,Part in ipairs(gamemodeClone.Tiles:GetChildren()) do
if Part:IsA("Part") then
Part.Transparency = 0
Part.CanCollide = true
end
end
if #tables.playersInRound <= 2 then
round = 0
print ("round "..round)
end
wait(3)
end
end)()
Please note that is this in a module.
I mean it kinda works (with bugs) but I feel like this is kinda a mickey mouse fix with the corountine.wrap
I tried doing while #tables.playersInRound > 1 do
instead of while true do
but it wouldn’t display the winner when the game was over.
I tried using many other loops like, repeat until
but none of those helped at all.
If you need more info with the code (winner function, etc) feel free to let me know.
1 Like
I already did a post like this before and not a single person replied. Please someone help it’s almost a month without a single reply:
https://devforum.roblox.com/t/doesnt-seem-to-declare-winner-when-gamemode-ends/1392937
What kind of bugs precisely???
Whenever someone wins, It still continues the loop which breaks the status bar. I think the way I wrote is not proper. I’m asking for a better way.
Alright I’ll take a look. [filler]
Feel free to ask me anything else if you want. (stuff such as winner function, how it works exactly, etc).
So there are three modules, this one being the mode, “Simon Says”?
no. There is a module and a regular script that runs the module functions. The module basically stores all the tables within functions.
Ex.
local tableFunctions = {
--- Add players --
AddPlayer = function(player, teleports, I)
end;
}
theres more tables like this. Its sorted out. You get what I mean right?
Not gonna lie, the script is giving me a little trouble:
Why is there a pound in #tables
if #tables.playersInRound <= 2 then
round = 0
print ("round "..round)
end
what you mean.
Ok so let me explain how my system works:
I first create a table with tables that store players ok?
local tables = {
playersInRound = {};
AfkPlayers = {}
};
Next I create another table in the module and add functions that play with those tables:
local tableFunctions = {
--- Add players --
AddPlayer = function(player, teleports, i)
-stuff
end;
PlayerLeft = function()
-stuff
end;
CheckWinner = function(parent, gameChosenClone)
-stuff
end;
-- theres more but I dont wanna post a lot lol
}
After I do that I create another table which contains the gamemodes:
local gamemodeFunctions = {
Classic = function(gamemodeClone)
-- do stuff
end;
Randomizer = function(gamemodeClone)
-- stuff again
end;
SimonSays = function(gamemodeClone, status)
-- stuff again
end;
}
And then from there I run everything in the regular script.
So the mod contains all three.
Yes. Everything is all in one.
It works all fine the problem is with the Simon says.
Ok I’m with you now. I’m more of a visual learner…
But yet again, what about the pound sign?
So do you have any idea on what the best loop could be for that scenario??
Maybe I should explain further,
So from the regular script I unpack my module of course:
local tableFunctions, otherFunctions, gamemodeFunctions, tables = unpack(require(game.ReplicatedStorage.GameModule))
and start a endless loop that runs the game
I think this might help you as well within the loop.
if gameChosenClone.Name == "Classic" then
gamemodeFunctions.Classic(gameChosenClone)
wait()
elseif gameChosenClone.Name == "Randomizer" then
gamemodeFunctions.Randomizer(gameChosenClone)
wait()
elseif gameChosenClone.Name == "SimonSays" then
wait()
gamemodeFunctions.SimonSays(gameChosenClone, status)
end
tableFunctions.CheckWinner(status, gameChosenClone)
wait()
tableFunctions.RemovePlayer()
wait()
gameChosenClone:Destroy()
I hope that helps.
Pound as in all the stuff within the table
If repeat until
doesn’t work I don’t know what to say
it only works once and then stops.
Sorry but I don’t know what else would work.
Do you know any other programmers that could help me??? I’ve been with the problem for over 2 months and I was discussing this here for almost a month now.