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

Which is the better one to use out of these 2 scripts?

So I just got into scripting and I was looking up how to change a bricks color when it's touched and I found 2 ways of doing that 1st script:

function onTouched() script.Parent.BrickColor = BrickColor.new("Bright red") end script.Parent.Touched:connect(onTouched)

2nd script:

script.Parent.Touched:connect(function(onTouched) script.Parent.BrickColor = BrickColor.new("Bright yellow") end)

I tested both of them and they both work the same, I was just wondering which one is easier to use.

1 answer

The first script is way more understandable / easier to edit as it's a function,

for example:

function Cool(stuff)
  if game.Players:FindFirstChild(stuff.Parent.Name) then
 print('PLAYER!')
 end
end


script.Parent.Touched:Connect(Cool)

it's easier to understand what goes on INSIDE a function than mashed together.

  • also makes debounce more understandable to new people learning lua since it's inside one function.

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