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.
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.
lua
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)
```