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

Help with if [variable] then statements?

Asked by 5 years ago

So when I see code such as this

local rebirth = game.Workspace.Events.Rebirth
 if rebirth then
    rebirth:FireServer()
end

Why is the variable inside the if/then statement. Everytime I've tried to learn what this means, I always think that it means if it sees the variable anywhere it runs. It always runs though, no matter what. Can someone explain this to me?

0
if will check to see if the provided condition is truthy - provided that rebirth is hooked to a valid object anywhere in your game, then it will be considered truthy. Your variable is essentially equal to true when called upon as a condition - purely because it exists. SummerEquinox 643 — 5y

Answer this question