Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to over-write tween properties not available for certain objects to keep code neat?

Hi everybody!

I'm making a lighting system of sorts with 2 parts to tween (neon parts and side gradients) and I wanna keep my serverside code neat (as pretty much everybody desires of course) but having 2 partproperties tables for each part is a bit unorganised for my standards, if I add both color values to it so it looks like this,

local partProperties = {
		ImageColor3 = Color3.fromRGB(R,G,B),
		Color = Color3.fromRGB(R,G,B),
}	

I will get an error when running the correct section of code I have for the side gradient lights and vice versa for the neon parts.

So in short, is there a way I can put overwrite tween properties not available for certain objects without having to create another partProperties table?

1 answer

Here's two alternatives:

If you have an out-of-sight-out-of-mind mentality, I recommend you use module scripts for this. If not, then you can nest a table within a table and reference them.

-- module script
local TweenProperties = {}

TweenProperties.Object1 = {
	Property1 = "example",
	Property2 = "example",
}

TweenProperties.Object2 = {
	Property1 = "example",
	Property3 = "example",
}

return TweenProperties

-- then in the script you want to use these tables in use require
local TweenProperties = require(pathToModuleScript)

print(TweenProperties.Object2.Property3) -- do functions

Otherwise nesting tables in tables:

-- in one script
TweenProperties = {
	Object1 = {
		Property1 = "example",
		Property2 = "example",	
	},
	Object2 = {
		Property1 = "example",
		Property3 = "example",
	},
}

print(TweenPropeties.Object2.Property3) -- do stuff

I lean in favour of module scripts. I use them all the time, and so does everyone else you can also use their functions/variables in multiple scripts. More on module scripts:

https://developer.roblox.com/en-us/api-reference/class/ModuleScript

This discussion is preserved as it was. New answers, comments, and votes are closed.