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

How do I use "or" in a variable?

Asked by
birds3345 177
4 years ago

I was looking around in the roblox dev forums and I saw this line of code that had a or in it, this is what I saw: ~~~~~~~~~~~~~~~~~ local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait() ~~~~~~~~~~~~~~~~~

I want to know how to use "or" in a variable

2 answers

Log in to vote
2
Answered by 4 years ago
Edited by JesseSong 3 years ago

Or in a variable checks in order from left to right for a value that is not nil and not false and will use either the first one that is not nil and not false or the last one in the line.

local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

This script will first check if the player's character already exists in the workspace. If the character is nil (not spawned), then it will wait until the player's character is spawned.

0
Refined grammatical errors, JesseSong! JesseSong 3916 — 3y
Ad
Log in to vote
1
Answered by
Filipalla 504 Moderation Voter
4 years ago
Edited 4 years ago

or will simply set the variable to the side which is truthy, in this case it will wait for the CharacterAdded event to fire until the character exists

Answer this question