#functions

12 messages · Page 1 of 1 (latest)

edgy bramble
#

Hey I made a function that makes parts change color but when I call the function then all three parts change colors 3 times.
function ChangeColor(functionspart, part2, part3)
functionspart = game.Workspace.FunctionsPart
part2 = game.Workspace.FunctionsPart2
part3 = game.Workspace.FunctionsPart3
functionspart.BrickColor = BrickColor.Random()
part2.BrickColor = BrickColor.Random()
part3.BrickColor = BrickColor.Random()
end

wait(5)

ChangeColor(1)

wait(2)

ChangeColor(2)

wait(2)

ChangeColor(3)

rapid quarry
#

Ill explain while ill show you.

#

First of all, you dont have to put this code in the function since the part only needs to be declared once.

#

Second of all, the functionspart, part2 and part3 are parameters that means when you call the function you have to assign them a value.

#

And third of all when youre calling the function youre putting a number while you need objects.

#

Give me one second to cook up the code.

#
local functionsPart = game.Workspace.FunctionsPart
local part2 = game.Workspace.Part2
local part3 = game.Workspace.Part3

function ChangeColor()
  functionspart.BrickColor = BrickColor.Random()
  part2.BrickColor = BrickColor.Random()
  part3.BrickColor = BrickColor.Random()
end

wait(5)
ChangeColor()
wait(2)
ChangeColor()
wait(2)
ChangeColor()
#

@edgy bramble

edgy bramble
#

I found another solution

rapid quarry
#

So solved?

edgy bramble
#

yes