Convert - Easy Ways To Convert Different Values!

Convert Module

Quick & easy data conversions

Setup:

  1. Open a new script in ServerScriptService.

  2. Require the module:

local Convert = require(6183613353)
  1. Use one of the methods listed below.

Methods:

Convert.UDim2ToVector2(udim2)

udim2 - Needs to be an UDim2 value

Convert.Vector2ToUDim2(vector2)

vector2 - Needs to be a Vector2 value

Convert.StringToBool(str)

str - Needs to be a string value

Convert.BoolToString(bool)

bool - Needs to be a boolean value

Convert.Color3ToBrickColor(color3)

color3 - Needs to be a Color3 value

Convert.BrickColorToColor3(brickcolor)

brickcolor - Needs to be a BrickColor value

Convert.Vector3int16ToVector3(vector16)

vector16 - Needs to be a Vector3int16 value

Convert.Vector3ToVector3int16(vector3)

vector3 - Needs to be a Vector3 value

Convert.Vector3ToCFrame(vector3)

vector3 - Needs to be a Vector3 value

Convert.CFrameToVector3(cframe)

cframe - Needs to be a CFrame value

GitHub

We now have a GitHub repository of the source code!

Conclusion

Thanks for stopping by to read this! If you have any ideas for more conversions, just PM me or reply with this copy-and-paste format:

## Idea
(Idea here)

See you with my next module!

Edit Log:

Open

14h - Added Convert.Vector3ToCFrame(vector3) & Convert.CFrameToVector3(cframe) and added a GitHub repo

11 Likes

These methods are mainly for if you want to do some quick conversions but don’t want to calculate them yourself. The two especially helpful methods in my opinion are the Color3 and BrickColor conversions, since I know I will need them a lot.

I don’t know if this has much purpose, since a lot of these are easily able to be recreated. And why does the module use : if it isn’t using self anywhere?

function Convert:StringToBool(str)
	if str == "true" or str == "false" or str == "nil" then
		local boolNew
		
		if str == "true" then
			boolNew = true
		elseif str == "false" then
			boolNew = false
		elseif str == "nil" then
			boolNew = nil
		end
		
		return boolNew
	else
		warn("Parameter must be a string!")
		return
	end
end

What is the point of this? And nil is not a boolean.

function Convert:BoolToString(bool)
	if bool == true or bool == false or bool == nil then
		local stringNew
		
		if bool == true then
			stringNew = "true"
		elseif bool == false then
			stringNew = "false"
		elseif bool == nil then
			stringNew = "nil"
		end
		
		return stringNew
	else
		warn("Parameter must be a boolean!")
		return
	end
end

Don’t see to much of a point in this either – literally just tostring(bool) – and once more, nil is not a boolean.

function Convert:Color3ToBrickColor(color3)
	return BrickColor.new(color3)
end

function Convert:BrickColorToColor3(brickcolor)
	return brickcolor.color
end

Is there a reason someone should use your wrapper over just constructing a BrickColor out of Color3 or indexing for the Color property directly?

function ConvertVector3int16ToVector3(vector16)
	return Vector3.new(vector16.X, vector16.Y, vector16.Z)
end

function ConvertVector3ToVector3int16(vector3)
	return Vector3int16.new(vector3.X, vector3.Y, vector3.Z)
end

You’re missing a ., so these are just global variables in the module that aren’t exposed to scripts that require it. And also, are Vector3int16s used that often outside of terrain stuff? Let alone any use cases for needing to convert a Vector3 to int16 or the other way around?

11 Likes

CFrame to Vector3

Hey there! Amazing module! I do have an idea. Is there a way to do Vector3 to CFrame and back?

1 Like

You could just use CFrame.Position and CFrame.new(Vector3).

1 Like

That’s exactly what I was going to use lol
Using the module for a simple function like that is kinda pointless tho since youre doing more work

It would be pretty cool if a GitHub repo existed for this, or you just directly gave us the source.

2 Likes

Yea lol just realized that using : is kind of unnecessary so let me change that rq.

(I do agree with you on this matter)

Although it is not a boolean, all scripters treat them somewhat as booleans, like in the statement if var == nil then return end.

Not all beginner scripters know how to do this. This module isn’t for advanced scripters, but rather to help out the beginners who still have a lot to learn.

There’s a first for anything. Someone may find a way for it to be helpful.

Yup need to fix that

Yes, I’ll do that right away. Give me around 5 minutes to fix the other errors and I’ll create a repo for the module.

No they don’t, they check if it’s nil, var == nil evaluates to a boolean expression.

They do know how to do this though, it’s literally documented and is a property on the brick color itself, and the overload that takes a Color3 is documented too. I think they’ll have a harder time using your module

You should probably state some use cases for that, I personally have seen udim2 → vector2 be somewhat popular use case so that one is alright.


I also recommend you use type annotations on your code

2 Likes

Both are now added!

Done :+1:

Removed nil

2 Likes

Thanks for the repo! Will be contributing some changes

2 Likes