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

Else statement does not respond. how do i fix it?

The if and elseif statements work when i tweak my variables but the final else statement does not work. Am i doing something wrong?

num = 1
num2 = 3

function ifStatement()
  if num > num2 then
	  script.Parent.Size = Vector3.new(2,2,2)

  elseif num == num2 then
	  script.Parent.Transparency = 0.3
	
  
  else
	script.Parent.Velocity = Vector3.new(1,0,1)
  end

end

ifStatement()

3 comments

0

i dont think u can do elseif and else in a if statement not sure

0

yes you can

0

The variable num would have to be less than num2 for the else statement to run.

1 answer

The final 'else' statement does work. IDK what the "Velocity" part of your script's parent (most probably a BasePart) does. You can add a print() function after

script.Parent.Velocity = Vector3.new(1, 0, 1)

Like this:

script.Parent.Velocity = Vector3.new(1, 0, 1)

print(script.Parent.Velocity)

It is going to print out the Velocity which, you guessed it, is 1, 0, 1. According to my knowledge, changing the velocity of a BasePart does nothing unless some special requirements are met. It just sets the Velocity, then waits for the requirement, most probably an instance, like BodyVelocity. Again, I am not sure what it does, so please correct me if you know.

Anyways, I hope my answer helped. Have a great day ahead!

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