How to create objects without oop?

Hello, I read that a lot of people hate OOP, but I basically don’t understand how I should do without it.

For instance, let’s imagine that we have 2 types of NPC, these 2 NPC share the same behaviors, but one does not take damage when we call TakeDamage on him, because of he is supposed to be unkillable. How is it possible to do this without OOP?

I’m a bit lost with this to be honest, any help would be appreciated!

1 Like

This can be easily resolved by ECS
it’s a system where there are components which you can put to any object you want.

However for your approach I’d suggest you just check if that pc is unkillable for instance you could give it an attribute bool named Killable. then play around with it :>

To add onto what @Countz872 said about the values, with the (kinda) new Attributes, you can also create your own properties. However when it comes to making your own objects, OOP is the best way to go, since you can add functions and other things that wouldn’t be possible with attributes or values.

As stated in the replies above, you could use attributes to determine if an enemy is killable or not. In my games, I have a separate module that handles damaging all enemies, so you could do something like this:

function module.Damage(enemy, damage)
    local hum = enemy:FindFirstChildOfClass('Humanoid')
    if (hum and not enemy:GetAttribute('Invincible')) then
        hum:TakeDamage(damage)
    end
end

Everything in Roblox is OOP. The stigma is that you shouldn’t need to create your own OOP system since it is messy in Lua, but you literally can’t make a game on roblox without OOP.

1 Like