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

"Else" statement does not seem to work?

Asked by 4 years ago
Edited 4 years ago

So my code looks like this :

while wait() do
if game:GetService("Workspace").Map then
   codeeeee
else
      print("ok")
end
end

Output :

Map is not a valid member of Workspace

Shouldn't it print ok until the map spawns in?

2 answers

Log in to vote
-1
Answered by
OBenjOne 190
4 years ago

I don’t know if this is the “right” way to do it but I usually use

  if workspace:FindFirstChild(“Map”) ~= nil then
 else
 end

This works for me...

0
let me try ItsBasicallyDenis -3 — 4y
0
it works tysmmmmmm ItsBasicallyDenis -3 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Just change the code to:

while wait() do
if workspace:FindFirstChild("Map") then
   --codeeeee
else
      print("ok")
end
end
0
Doesn't work ItsBasicallyDenis -3 — 4y
0
Any errors? Where is your script located? itz_rennox 412 — 4y
0
works for me itz_rennox 412 — 4y
0
I think FindFirstChild returns nil if there is no child with that name. OBenjOne 190 — 4y
View all comments (4 more)
0
So maybe nil does not equal false or true and causes an error? OBenjOne 190 — 4y
0
It works for me itz_rennox 412 — 4y
0
what about workspace.Map? i think that shoudl work right? Erie20 102 — 4y
0
Erie20, workspace.Map wont work, but the strange thing is that my way dont worked for him which is kinda strange cuz it should work (Cuz im always using that way and its working for me) itz_rennox 412 — 4y

Answer this question