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

else not working when checking for variable existence. any help?

Asked by
i_geeb 0
2 years ago
Edited 2 years ago
 local tool
    if not tool then
        print"e"
       else
    print"c"
end

it won't print "c" whatever I change 'tool' to, any help appreciated

1 answer

Log in to vote
0
Answered by
Psudar 882 Moderation Voter
2 years ago
Edited 2 years ago

I assume you're trying to assign a variable named tool to whatever value the ternary statement evaluates to? If this was the exact code you used, then you missed an equal '=' operator during the assignment.

local tool = if not tool then print("e") else print("c") 

Keep in mind, however, that this only works if the tool is nil or false. Also, the variable named tool will be reassigned to whatever print() returns.

0
I also included parenthesis on the print function just for clarity. You can omit them for strings if you want Psudar 882 — 2y
0
it's more like checking if a block exists in a game. if game.workspace.part then <- guessing this checks if a part exists i_geeb 0 — 2y
0
if you want to check if a block exists in workspace, you can use Part:IsDescendantOf(workspace) Psudar 882 — 2y
Ad

Answer this question