Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

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

Asked by 6 years ago

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?

0
You could create your own statistic GUI but as far as I know, creating custom properties for anything is impossible. User#2146 0 — 6y

2 answers

Log in to vote
0
Answered by
arshad145 392 Moderation Voter
6 years ago

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."

Ad
Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
6 years ago

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!

Answer this question