Is there better way to make sure numbers doesnt go over wanted max/min?

		local FinalPosition = Vector2.new(CurrentPosition.X + value.X, CurrentPosition.Y + value.Y)
		
		if FinalPosition.X > 8 then
			FinalPosition = Vector2.new(8, FinalPosition.Y)
		end
		
		if FinalPosition.X < 0 then
			FinalPosition = Vector2.new(0, FinalPosition.Y)
		end
		
		if FinalPosition.Y > 8 then
			FinalPosition = Vector2.new(FinalPosition.X, 8)
		end
		
		if FinalPosition.Y < 0 then
			Vector2.new(FinalPosition.X, 0)
		end

is there a way to automatically cap a number from going Over 8/ under 0? Or is this one above a good method?

look into math.clamp(), heres the documentation:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.