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

How do I use "or" in a variable?

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

✓ Accepted answer

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.

1 comment

0

Refined grammatical errors, JesseSong!

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

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