I am working on a game and I am trying to make a part where it randomly breaks. Here is my script:
local number = math.random(1,5) local part = script.Parent if number = 4 then part:Destroy() end
Help would be appreciated!
Ya made the mistake of not putting 2 equals in.. Oops..
It's supposed to be:
if number == 4 then part:Destroy() end
Whenever you use "if" and an equals sign, there must be two equal signs.
In a simpler way:
if number == 4 then part:Destroy() end
Even though there was 2 answers, I wanna state that one equal means for "set". Two equals means for "equals to". So using one equals sign in an if statement, it does not work and always return false. It is because if statement never get pass the requirement of setting the number to 4 in the if statement and it never will.
Also, if statement only runs once, means that if the number randomize and its 1, 2, 3 or 5, it won't repeat for you and it stops. You need to make a loop and cover them all up.
Script:
local RandomNumber = math.random(1,5) local Part = script.Parent if RandomNumber == 4 then Part:Destroy else -- If the number is not 4, then do what code. You can delete the "else" if you do not want this. end