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

Is there a way to set custom properties for humanoids? (Armor Health, Psyche, etc)

Ello! I'd just like to know if there was a way you could script custom properties for humanoids. For example, a Humanoid has 100 health, but how do you make it have 100 of something else?

1 comment

0

You could create your own statistic GUI but as far as I know, creating custom properties for anything is impossible.

2 answers

Sorry , we cannot make scripts for you but we can give you ideas.

A Wonderful place to learn!

Try using "Graphical User Interfaces" : GUIs , NumberValue , a custom leaderboard if you can, become creative don't always rely on people.

Sorry if I sound rude.

Shakespeare said that : "We need to be cruel to be kind."

You can't change the properties that a Humanoid Object has. It is an uneditable userdata.

You can however, use a wrapper or higher object that a Humanoid is a part of.

A wrapper is just a table with the Humanoid inside it, that references the Humanoid as a backup.

local Humanoid = {
	new = function(Humanoid, Parent)
		return setmetatable({Humanoid or Instance.new("Humanoid", Parent)}, Humanoid)
	end;
}
Humanoid.__newindex = Humanoid

function Humanoid:__index(i)
	local Humanoid = self.Humanoid
	local Variable = Humanoid[i]
	if type(Variable) == "function" then
		local func = Variable
		function Variable(...) -- We need to wrap functions to mimic ":" syntax
			return func(Humanoid, select(2, ...))
		end
		-- Make it so the table can directly call the above function
		-- Instead of having to recreate the function each time
		rawset(self, i, Variable)
	end
	return Variable
end

With this you could "add custom properties to humanoids", but you would have to reference these tables

I repeat, if you reference the Humanoid in the workspace, the above table will not be read

P.S. The best way to share tables is through ModuleScripts

More information on Object-Oriented Programming can be found here

local PlayerHumanoid = Humanoid.new(workspace.Player.Humanoid)
PlayerHumanoid.Armor = 15

Good luck!

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