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

Did I indent the right part?

I made a part and put in a script and a value. I wanted something to happen if the value got to zero but whenever it got to zero nothing happened. I put this in the script

script.Parent.Touched:Connect(function(hit)
if script.Parent.Value.Value > 0 then
if hit.Parent.Name == "Hammer" then
script.Parent.Value.Value = script.Parent.Value.Value - 10
else if script.Parent.Value.Value <= 0 then
print("k")
end
end
end
end)

it didn't work I think it is because of the second and fourth line. To fix the problem I tried indenting the 2 lines below the second line but it still wouldn't work. I also tried indenting the second last line none of them worked.

5 comments

0

i assume because the elseif that cecks if its zero gotta match up with the first if statment that checks if its bigger than zero

0

and youre putting that elseif with the hamme check, which is wrong i guess

0

what? how do I do that?

0

On the second line, try using == instead of >, you are detecting if the value is higher than 0 if you use > instead of ==

0

oh I see anything else?

1 answer

Mistakes

  1. You used > which detect if the value is higher than zero, you might be looking for == instead which detect if the value is 0
  2. You included the "elseif" statement on the second statement instead of the first statement.
  3. You seperated the "else" and the "if", you might be looking for the "elseif" statement.
script.Parent.Touched:Connect(function(hit)
	if script.Parent.Value.Value == 0 then
		if hit.Parent.Name == "Hammer" then
			script.Parent.Value.Value = script.Parent.Value.Value - 10
		else return end
	elseif not script.Parent.Value.Value == 0 then
		print("k")
	end
end)

2 comments

0

actually I want to check on the second line if it is higher than 0 and on the 6th line if it is 0 

0

I think it is because it is a tool

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