I made a tycoon without someone else's pack and I hit a road block

So i started I think it’s going good but I’m trying to make it easy to duplicate around the map on completion but It is really hard to comprehend everything I’m doing it seems kind of unorganized to me if you have any feedback let me know, here is the Model:

Right off the bat, before looking at the model, if it’s hard to read I recommend commenting A LOT. Even if it’s simple try to comment every couple lines so that you never have to read too much to remember what each part does. I will reply again after I look into the model but yes:

Commentsss

this is not in the right category. It should be in cool creations.

Okay before I give feedback I just wanted to pointed out that:

  1. My feedback is just personal opinion from what I do, there’s no right or wrong in coding and whatever works for you is good.

  2. Make sure to post in the right forums: this is more of a Code Review than a Scripting Support post

My Feedback

  • When I code, having too many scripts scattered across the world can make it hard to keep track of what each does, so I keep Scripts in ServerScriptService and Local Scripts in StarterPlayerScripts or StarterCharacterScripts (depending on if I need scripts to reset on death or not)

  • I also go for an OOP approach, which if you don’t know about I highly recommend you read up on it here. I will also put a copy-pasta I wrote myself to simplify how OOP works in Roblox. I recommend it because Tycoons would go PERFECTLY with OOP. The Tycoon, Data, and Blocks can all be Objs and it’s also a good starting point to OOP in my opinion.

  • At the beginning of each script, I would add a Header as well as at the beginning of each function. For example:

Template

--[[
   scriptTitle
      description

   --
   bin (if applicable)

   --
   other attributes for the script
]]

Example

--[[
   TycoonScript
      handles the tycoon giver system
  
   --
   bin

   .new()
   :GiveTycoon()
   :SellTycoon()
]]

Object Oriented Programming

Overview

As in with other OOP languages, Lua can create objects using metatables to create “classes” and then have functions to work on those objects.

Creating base class

local baseObj = {}
baseObj.__index = baseObj

function baseObj.new()
	local newBaseObj = setmetatable({}, baseObj)
	newBaseObj.Value = 10
	return newBaseObj
end

function baseObj:GetValue()
	return self.Value
end

return baseObj

Creating child class

Child classes can overwrite default values from parent class as well as it’s subroutines!!

local baseObj = require( [path.to.baseObj] )

local childObj = {}
childObj.__index = childObj
setmetatable (childObj, baseObj) -- childObj has access to baseObj functions

function childObj.new()
	local newChildObj = setmetatable(baseObj.new(), childObj) -- using constructed baseObj
	newChildObj.Value = 12 -- overwrites default value from baseobj
	return newChildObj
end

Now, calling childObj:GetValue() will return 12 as it’s been overwritten.

1 Like

No I have a legitament question because i hit a road block

oh sorry about that. I skimmed through your post. Ha ha.

1 Like