City Tycoon Devlog

You can use F9 in-game to bring up the Developer console.

1 Like

Hey, I’m still looking into the lag problem and figured, why not just hand over the code so someone can help me optimize it. So here it is, any ideas why it might be lagging?

local npcModule = require(game.ReplicatedStorage.Modules.NPCModule)

for i, tycoon in pairs(workspace.Tycoons:GetChildren()) do
	if tycoon.Name ~= "EmptyTycoon" then
		for i, place in pairs(tycoon:GetChildren()) do
			if place.Name ~= "House" and place.Name ~= "Island" then
				local npcs = place.NPCs
				local max = npcs.Max

					while wait(wait(math.random(npcs.MinimumWait.Value, npcs.MaximumWait.Value))) do
						if #npcs.Bots:GetChildren() < max.Value then
							local bot = npcModule.Create(npcs.Spawn.Position, npcs.Bots)
							local position = npcModule.CalculatePath(bot, place)
							npcModule.Move(bot, position)	
1 Like

it appears for this script you have no garbage collection, it will probably spawn bots for even unowned plots. If you have plots being loaded by players you could make a way to cancel the coroutine whenever the plot gets unloaded… Plus your resuming a coroutine directly outside of the creation, you could reference the coroutine object so you can task.cancel it later

local Thread = coroutine.create(function()


task.cancel(Thread)--stops the thread entirely

or if you don’t want to resume the coroutine you could just use task.spawn to execute it immediately

local Thread = task.spawn(function()



Suggestion: Add taxing. After afew days or so you will get taxed depending on each building that you place. example: smol store will give you 1% tax but the big store will give you 5% tax

I see where your coming from although I have some bad experience with a system like this in another game. I believe the game was called business tycoon or something, but that is irrelevant. This game implemented this feature, where you would have to pay tax every 10 minutes, now don’t get me wrong this is a very cool feature to have, but it does two different things depending on age:

  • Older Players - they understand the system and how it works, and it gives them stress that they’ll miss the deadline or not have enough money when it’s time to pay it.
  • Younger Players - they have no idea what a tax even is, all it is is a timer counting down that wants money. My best guess is that they think it is some doomsday device that when it goes off they lose a bunch of money :sweat_smile:. It’s pretty funny to think about, but when they experience this they easily get mad and start asking people why it does this in chat, and sometimes even dislike the game and never come back.

Now if you have solutions to these problems I’d be more then happy to implement this, it’s just that these problems with the system could make this feature game breaking!

1 Like

Sorry if I sound stupid :sweat_smile:

In your reply you were referencing task instead of courotine(or however you spell it…), I know that when using courotine it allows you to run multiple loops at once, does task do the same thing? I’ve never used task before but I’m eager to learn!

I have an idea, there will be a GUI that pops up when a new player joins. It tells them about the tax system, but heres the catch they can either enable the tax system or disable it. If the enable it the will have tax BUT they will get 15% (or so) more income. If they decide not to, no tax and no increased income

(But still you do you, the game sounds really amazing!)

1 Like