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

Is this the right way to script this?

if game.Workspace.Part1.BrickColor = BrickColor.new("White") then
game.Workspace.Part1.BrickColor = BrickColor.new("Black")
end

I'm a alright scripter but the if, then, else, elseif have always confused me when it comes to coding

1 answer

✓ Accepted answer

When you're comparing stuff, like if game.Workspace.Part.Anchored = true that would be incorrect. You have to use == to see if something is true. Also things like else and elseifcan be very useful in an if function. For example;

if game.Workspace.Part.Anchored == true then
	print 'part is anchored'
else
	print 'part is not anchored'
end

So you see what else is used for? Basically if that isn't true. elseif is used like this:

if game.Workspace.Part.Anchored == true then
	print 'part is anchored'
elseif game.Workspace.Part2.Anchored == true then
	print 'part2 is anchored'
end

So basically you can use to if's in one function! Pretty useful right?

I hope you understand if functions and comparing objects! Also if this helped please accept the answer and a little credit would be nice :)

1 comment

0

Thank you! :D

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