Functions that look like "Part:Change(Color)"?

Hello!

I was wondering, is it possible to have functions that look like Variable:Change(Color)?

Here would be an example.

local Part = script.Parent;
Part:Change("Really black");

I’ve tried making one but I just don’t know how to make it work.

This might be more work for whats possible and I would like roblox to add a system to add custom methods but currently this is the only way to do so and it involves metatables etc

2 Likes

You can do this with modules.
Modules have a system where you can do in the module script

function module:Change(Part,Color)
Part.Color = Color
end

1 Like

Using a ModuleScript like @SirHammerWorks said is a good idea and an easy alternative to making methods for the Part class. Keep in mind that you’re going to need to instantiate a new BrickColor in the function if you intend to simply input the name of a BrickColor as an argument.

function Change(Part,Color)
	if(Part:IsA("BasePart")) then --checks if the first parameter is a part
		Part.BrickColor = BrickColor.new(Color)
	end
end