Is it possible to create and assign a custom keyword?

Pretty simple. Would it be possible to create a keyword in the script editor that’s global to all scripts in the game. Say I wanted to make a kill(insert humanoid instance here) function that I don’t want to have to write each and every time I make a new script. While my example is pretty redundant I feel for other complex and/or longer functions it’d save space or time.

_G

script 1:

_G.Variable = false;

script 2:

print(_G.Variable)

I wouldn’t recommend it though, I don’t even use it.

I think I read this wrong lol, could you explain a bit?

Say I wanted a keyword. Something like wait() but instead of waiting or being called “wait” I wanted to name it “kill()” and have it set a humanoid’s health to 0.

There’s functions, which you can use

local function Kill()
    --<Kill
end;

But you said you want the call it from any script? like a built in roblox object? I can’t remember the exact name for things like these, but you can’t.

Closest you can get to your own custom ‘class’ is by using module scripts

1 Like

Well there’s many ways of making a global function but you can’t implement keywords on your own.

You can use:
-ModuleScripts
-Global Variables
-actually i think thats it

But the fastest way is as @MightTea said - global variables.

Yes there is controversy over them, so it’s your choice. But here’s how you do it:

function _G:Kill(humanoid)
   Humanoid.Health = 0
end


---other script

_G:Kill(character.Humanoid)

This can be called anywhere on the same machine. This means that if you set the global variable on the server, it will only affect the server. If you set it on a client, it will only affect that client.

3 Likes

Considering all of this, then I feel it’d be best to just use modules. They’re a bit more organized anyway!

There is no speed difference between _G variables and module scripts. Modules are the preferred method because they result in less spaghetti code than _G.

Additionally, you shouldn’t be using : for a function like this, because it’s a free function and not a method.

1 Like

Aren’t exploiters also able to “read” _G functions?

That’s fair and I was being sloppy. And by speed I meant implementation-wise. With a module you have to call require but with global variables you just call _G.

So long story short don’t do it the quick and easy way because that’s just lazy and messy

Not that modules are any harder

Exploiters can decompile, tamper, and mess with every single function on their client, whether in _G or elsewhere. As long as it’s on their client, it’s accessible.

3 Likes