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

What does this fire script mean? It is confusing(variables)

function lightOnFire(part) fire = Instance.new("Fire") fire.Parent = part end

firePart = game.Workspace.FirePart firePart.Touched:connect(lightOnFire)

what does it mean by fire.Parent = part?

And how does it know which part it is?

2 answers

lightOnFire is a function.

Functions take in some values, do something with those values, then can choose to output some values.

The values to take in are between the () in the function definition; in this case, it takes in a part.

Thus if I were to call lightOnFire(workspace.Baseplate), lightOnFIre would run with part as workspace.Baseplate.

When you connect lightOnFire to a Touched event with firePart.Touched:connect(lightOnFire), that means "call this function with the part that touhed firePart whenever it gets touched".

Please, PLEASE use a code block. They make this much nicer!

print("Hello world!")

Ok, so moving on. This is a variable. So you can do this!

local Info = "123456"
print("The info is"..Info.."!")
if Info < 1234567 then
	print(Info.." is less than 1234567!")
end

What this will do in the output is say "123456" and "123456 is less than 1234567!" But this is not only used for print and if's statements, it can be used for much more as a debounce, shortcut in scripting, and easy acess to something! Like this

local IsScriptRunning = false -- debounce. A debounce should be used like on clicked and touched functions.

function Clicked()
	if IsScriptRunning == false then
		local IsScriptRunning = true -- Make it impossible to go through the if statement.
		print("Yay it works!")
		local Brick = game.Workspace.Part
		Brick.BrickColor = BrickColor.new("Lime green")
		local IsScriptRunning = false --Makes the function useable.
	end
end

script.Parent.MouseButton1Click:connect(Clicked)

So those were some basic examples, so variubles can also be used as this. And some scripts have lots of variubles, so there not junk. Like in a tycoon script

local Tycoons = {}
local Teams = game:GetService('Teams')
local Settings = require(script.Parent.Settings)
local BC = BrickColor
local Storage = Instance.new('Folder', game.ServerStorage)
Storage.Name = "PlayerMoney"
Instance.new('Model',workspace).Name = "PartStorage" --  parts dropped go in here to be killed >:)

function returnColorTaken(color)
	for i,v in pairs(Teams:GetChildren()) do
		if v:IsA('Team') then
			if v.TeamColor == color then
				return true
			end
		end
	end
	return false
end
--run this first so if there is a 'white' team it is switched over
if not Settings['AutoAssignTeams'] then
	local teamHire = Instance.new('Team', Teams)
	teamHire.TeamColor = BC.new('White')
	teamHire.Name = "For Hire"
end

for i,v in pairs(script.Parent:WaitForChild('Tycoons'):GetChildren()) do
	Tycoons[v.Name] = v:Clone() -- Store the tycoons then make teams depending on the tycoon names
	if returnColorTaken(v.TeamColor) then
		--//Handle duplicate team colors
		local newColor;
		repeat
			wait()
			newColor = BC.Random()
		until returnColorTaken(newColor) == false
		v.TeamColor.Value = newColor
	end
	--Now that there are for sure no duplicates, make your teams
	local NewTeam = Instance.new('Team',Teams)
	NewTeam.Name = v.Name
	NewTeam.TeamColor = v.TeamColor.Value
	if not Settings['AutoAssignTeams'] then
		NewTeam.AutoAssignable = false
	end
	v.PurchaseHandler.Disabled = false
end

function getPlrTycoon(player)
	for i,v in pairs(script.Parent.Tycoons:GetChildren()) do
		if v:IsA("Model") then
			if v.Owner.Value == player then
				return v
			end
		end
	end
	return nil
end

game.Players.PlayerAdded:connect(function(player)
	local plrStats = Instance.new("NumberValue",game.ServerStorage.PlayerMoney)
	plrStats.Name = player.Name
	local isOwner = Instance.new("ObjectValue",plrStats)
	isOwner.Name = "OwnsTycoon"
end)

game.Players.PlayerRemoving:connect(function(player)
	local plrStats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
	if plrStats ~= nil then
		plrStats:Destroy()
	end
	local tycoon = getPlrTycoon(player)
	if tycoon then
		local backup = Tycoons[tycoon.Name]:Clone()
		tycoon:Destroy()
		wait()
		backup.Parent=script.Parent.Tycoons
	end
end)

So yeah, that's how important variubles are.

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