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

Why isn't my "if" statement executing the code?

Asked by 7 years ago
Edited 7 years ago

I am making a game heavily based off of BuildIntoGames', "Guest Defense", and the if statement isn't working so that it can end the wave!

1while true do
2    if(game.Workspace.Enemyskilled.Value == 8) then
3    print("Wave 1 finished")
4    randomSong:Stop()
5    script.Voice:Play()
6    player.PlayerGui.Wave1:Remove()
7    end
8    end

1 answer

Log in to vote
0
Answered by 7 years ago

In a while true do loop you must add wait() or else the code will crash causing Studio to crash (possibly)

What I suggest you do is label all the variables;

1local randomSong = -- your variable
2local V = script:WaitForChild('Voice')
3local plr = game.Players.LocalPlayer

remember you can use the player in local scripts!

If that script is only part of your code then, please add the rest in.

Anyway, the script should look like this if you have all your variables;

01local variables
02 -- insert all variables
03while true do
04    wait(1)
05     if(game.Workspace.Enemyskilled.Value == 8) then
06         print("Wave 1 finished")
07         randomSong:Stop()
08             script.Voice:Play()
09         player.PlayerGui.Wave1:Destroy() -- Do not use :Remove() use :Destroy()
10           end
11    end

If you are able to add all variables and make sure this is a local script and all then your good to go!

Anyway, this is basically a model for you to learn on why your script isn't working.

  1. You probably didn't add wait()
  2. you probably got the variables wrong
  3. this is probably a server script, that's why player doesn't work

If you checked through all of those then your code should work

If I helped then please accept answer ;)

Good luck and have fun developing!

Ad

Answer this question