Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Is this the right way to script this?

Asked by
Prioxis 673 Moderation Voter
10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
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

Log in to vote
4
Answered by 10 years ago

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 :)

0
Thank you! :D Prioxis 673 — 10y
Ad

Answer this question