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

Is it possible to have a variable assigned to code?

Hello, I am not allowed to post on the dev fourm due to my rank so I'm posting here. Anyways I am trying to make a event that happens in my game, but I'm wondering if you can shorten code? Like with variables you can do

local part = workspace.Part

so it can shorten the code. So you don't have to type

workspace.Part.BrickColor

instead you can say

part.BrickColor

But I am wondering if you can do that with code, Ill give you an example:

local fire = if game.Workspace.Fireworks1.FireworksClassicStyle.Trigger.Value == false then
	game.Workspace.Fireworks1.FireworksClassicStyle.Trigger.Value = true
	else
		game.Workspace.Fireworks1.FireworksClassicStyle.Trigger.Value = false
	end 

so instead of my copying and pasting that (which I would probably have something else copied already) I would just type "fire" and the firework launcher would fire a rocket. If you can't make a "code varible" that way then is there any way? I havent seen any of those in the code in free models Ive learnt from. So that doesn't give my that much hope that is exists. But even if it does/doesn't, thanks for your help!

1 comment

0

Just put your code into a function and then call it

1 answer

✓ Accepted answer

Define Code in a function:

function MyFunction()
if ImDumb == true
then
print("I am Dumb")
end
end

If you need it later, call it with the name of the function:

MyFunction()

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