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

Is there any simple and easy way to convert a player's ID into a vector3?

I'm tossing around the idea of making a Dragon Ball game. In Dragon Ball however, everyone's Ki--their life force or mana or whatever--manifests as a different colour, and each person's Ki feels different to someone who can sense it.

Sometimes these differences are minute, but they're always present.

So, is there any quick and easy(i.e. not super math-y) way to convert a player's userID into a Vector3 value to become their unique Ki colour?

1 comment

0

Look up Color3 on the wiki. This might help.

1 answer

✓ Accepted answer

While that isn't possible without hacky methods like tostring, tonumber, and string.sub being combined with Vector3's-

Wrote the coded & commented it; untested, and it may or may not work. But something like this definitely will!

_G.Colors = {} --\\Make a table of colors already used. In _G, too, so any script can get a players color.

local Start = 1 --\\Minimum color

local End = 64 --\\Maximum color

math.randomseed(tick()) --\\Set the random generation seed, makes the result seem more random.

local function TableHasValue(Ki) --\\Define the function for checking if a Ki is used.

	for Index, Info in next, _G.Colors do --\\Loop through used Ki's

		if (Info[2] == Ki) then --\\If it is taken then..

			return true --\\It's taken; return true. Find a new Ki.

		end --\\End the if statement.

	end --\\End the loop

	return false --\\Nothing found, it's untaken; return false. Not necessary but I like to always have an explicit return value, not implicit (nil or otherwise).

end --\\End the function definition.

local function GenerateKi() --\\Define a getKi function.

	local CurrentKi --\\Define an empty variable to the ki

	repeat --\\Start a loop

		CurrentKi = BrickColor.palette(math.random(Start, End)) --\\Select another random Ki

	until (not TableHasValue(_G.Colors, CurrentKi)) --\\Stop if it's an untaken color

	return CurrentKi --\\Return the Ki

end --\\End the function.

--[[
	Example use:
	_G.Colors[#_G.Colors + 1] = {Player.Name, GenerateKi()}

	INFO:

	To get it as a GUI Color (Color3) simply do GenerateKi().Color

	Ki's are formatted as {PlayerName, KiColor}

	If there are more players than the possible amount of colors, it WILL crash!
]]--

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